@@ -14,56 +14,52 @@ ReactPHP bindings around ext-parallel-infinite-pool
1414To install via [ Composer] ( http://getcomposer.org/ ) , use the command below, it will automatically detect the latest version and bind it with ` ~ ` .
1515
1616```
17- composer require react-parallel/infinite-pool
17+ composer require react-parallel/infinite-pool
1818```
1919
2020## Usage ##
2121
22- The following example will spin up a thread with a 1 second TTL clean up policy. Meaning that threads are kept around
23- for 1 second waiting for something to do before closed. It then runs a closure in the thread that will wait for one
24- second before returning an message. Upon receiving that message the mean thread will echo out that message before
22+ The following example will spin up a thread with a 1 second TTL clean up policy. Meaning that threads are kept around
23+ for 1 second waiting for something to do before closed. It then runs a closure in the thread that will wait for one
24+ second before returning an message. Upon receiving that message the mean thread will echo out that message before
2525closing the pool;
2626
2727``` php
28- use React\EventLoop\Factory;
2928use ReactParallel\EventLoop\EventLoopBridge;
3029use ReactParallel\Pool\Infinite\Infinite;
3130
32- $loop = Factory::create();
33- $infinite = new Infinite($loop, new EventLoopBridge($loop), 1);
34- $infinite->run(function () {
35- sleep(1);
31+ $infinite = new Infinite(new EventLoopBridge(), 1);
3632
37- return 'Hoi!';
38- })->then(function (string $message) use ($infinite) {
39- echo $message, PHP_EOL;
33+ Loop::futureTick(async(static function () use ($infinite) {
34+ echo $infinite->run(function () {
35+ sleep(1);
36+
37+ return 'Hoi!';
38+ }), PHP_EOL;
4039 $infinite->close();
4140});
42- $loop->run();
4341```
4442
4543## Metrics
4644
4745This package supports metrics through [ ` wyrihaximus/metrics ` ] ( https://github.com/wyrihaximus/php-metrics ) :
4846
4947``` php
50- use React\EventLoop\Factory;
5148use ReactParallel\EventLoop\EventLoopBridge;
5249use ReactParallel\EventLoop\Metrics as EventLoopMetrics;
5350use ReactParallel\Pool\Infinite\Infinite;
5451use ReactParallel\Pool\Infinite\Metrics;
5552use WyriHaximus\Metrics\Configuration;
5653use WyriHaximus\Metrics\InMemory\Registry;
5754
58- $loop = Factory::create();
5955$registry = new Registry(Configuration::create());
60- $eventLoopBridge = (new EventLoopBridge($loop ))->withMetrics(EventLoopMetrics::create($registry));
61- $finite = (new Infinite($loop, $eventLoopBridge, 1.3))->withMetrics(Metrics::create($registry));
56+ $eventLoopBridge = (new EventLoopBridge())->withMetrics(EventLoopMetrics::create($registry));
57+ $infinite = (new Infinite($eventLoopBridge, 1.3))->withMetrics(Metrics::create($registry));
6258```
6359
6460## License ##
6561
66- Copyright 2020 [ Cees-Jan Kiewiet] ( http://wyrihaximus.net/ )
62+ Copyright 2025 [ Cees-Jan Kiewiet] ( http://wyrihaximus.net/ )
6763
6864Permission is hereby granted, free of charge, to any person
6965obtaining a copy of this software and associated documentation
0 commit comments