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 16, 2018 · 5 revisions

WORKER SERVICE

This kind of 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 should restore if a change made in a request and harm the next request

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

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

WORKER SERVICE and coroutine: COROUTINE-FRIENDLY SERVICE

If you use coroutine in your code, it must be also a COROUTINE-FRIENDLY SERVICE.

  1. its vars will not change in any requests

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

Refactor

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

method 1: making new classes extending old classes

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

method 2: making new files replacing old files

service official refactor
app() Illuminate/Foundation/Application.php LaravelFly-fly-files/src/Application.php

WORKER OBJECT

refactor can work on any other objects like a WORKER SERVICE.

object official refactor
Facade Illuminate/Support/Facades/Facade LaravelFly-fly-files/src/Facade.php
Clone this wiki locally