launch()

Here use IO mode to run tasks through threads separate from the main thread.

You should include inside that is a callback, not let it be a generator.

$scope = new CoroutineScope(Dispatchers::IO);

$scope->launch(function () {
    echo "Coroutine 1\n";
});

$scope->launch(function () {
    echo "Coroutine 2\n";
});

CoroutineGen::runBlocking($scope);

Last updated