phasync
Swerve / onWorkerStart

Method

Swerve::onWorkerStart

Run $callback in every worker as it starts, before the application loads, inside the worker's event loop, so it may start coroutines that run for the worker's life. Register it the way Swerve::ini says; calls after startup change nothing. A callback that throws stops the worker, as an application that fails to load does.

Description#

public static Swerve::onWorkerStart(
    Closure $callback
): void

Parameters#

$callback Closure

Examples#

Example 1
// a file in your package's composer.json "files"
Swerve::onWorkerStart(function () {
    phasync::go(function () {
        while (true) {
            refresh_feature_flags();
            phasync::sleep(60);
        }
    });
});