Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

WORKER SERVICE and WORKER OBJECT

scil edited this page Sep 9, 2018 · 5 revisions

WORKER SERVICE

This type of service is also called COROUTINE-FRIENDLY SERVICE, as LaravelFly uses coroutine in Mode Map.

A COROUTINE-FRIENDLY SERVICE that must satisfy folling conditions:

  1. singleton. A singleton service is made by by Illuminate\Containe\Application::singleton() or Illuminate\Containe\Application::instance()

  2. its vars will not change in any requests

  3. if it has ref attibutes, like app['events'] has an attribubte container, the container must be also A COROUTINE-FRIENDLY SERVICE

If a singleton service does not satisfy the second condition, you can try refactor.

There are two Traits LaravelFly\Map\Util\Dict and LaravelFly\Map\Util\StaticDic used by LaravelFly to make a service to be a COROUTINE-FRIENDLY SERVICE. The first trait handles non-static vars, while the second static vars.

There two simple examples which make Laravel's official service coroutine-friendly.

service official refactor
app['event'] Illuminate\Events\Dispatcher LaravelFly\Map\IlluminateBase\Dispatcher
app['translator'] Illuminate\Translation\Translator LaravelFly\Map\Illuminate\Translation\Translator

WORKER OBJECT

Any other objects can be COROUTINE-FRIENDLY if they work like a WORKER SERVICE.