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