value++; } }; $context = ContextBuilder::create() ->withCleanupInterval(Interval::seconds(0.5)) ->build(); $context->on('worker_stopped', [$counter, 'increment']); $context->on('no_workers_remaining', [$context, 'stop']); $context->on('stopped', fn() => printf("\nJobs completed: %d\n", $counter->value)); for ($i = 0; $i < NUM_JOBS; $i++) { $context->submit(fn() => sleep(3)); print('.'); } $context->run();