Extract components and add more tests
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use Toalett\Multiprocessing\ConcurrencyLimit;
|
||||
use Toalett\Multiprocessing\ContextBuilder;
|
||||
use Toalett\Multiprocessing\Task\Interval;
|
||||
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
@@ -16,20 +17,23 @@ class Job
|
||||
|
||||
public function __invoke()
|
||||
{
|
||||
cli_set_process_title('php ' . $this->title);
|
||||
print("start:{$this->title}\n");
|
||||
sleep(3);
|
||||
print("stop :{$this->title}\n");
|
||||
cli_set_process_title("php {$this->title}");
|
||||
print("+ {$this->title}");
|
||||
sleep(1);
|
||||
print("\r {$this->title}\n");
|
||||
}
|
||||
}
|
||||
|
||||
$limit = ConcurrencyLimit::singleWorker();
|
||||
$context = ContextBuilder::create()->withLimit($limit)->build();
|
||||
$context = ContextBuilder::create()
|
||||
->withLimit(ConcurrencyLimit::singleWorker())
|
||||
->withCleanupInterval(Interval::seconds(0.2))
|
||||
->build();
|
||||
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
$title = md5(mt_rand());
|
||||
$context->submit(new Job($title));
|
||||
}
|
||||
|
||||
$context->on('no_workers_remaining', fn() => $context->stop());
|
||||
$context->on('no_workers_remaining', [$context, 'stop']);
|
||||
$context->run();
|
||||
|
||||
Reference in New Issue
Block a user