Skip to content

Commit 0100181

Browse files
authored
Merge pull request #5 from reactphp-parallel/add-documentation
Add Documentation
2 parents 773123b + bf1e2d8 commit 0100181

7 files changed

Lines changed: 32 additions & 22 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2019 Cees-Jan Kiewiet
3+
Copyright (c) 2020 Cees-Jan Kiewiet
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,29 @@ To install via [Composer](http://getcomposer.org/), use the command below, it wi
1717
composer require react-parallel/limited-pool
1818
```
1919

20+
## Usage
21+
22+
Just like any other `react-parallel` the limited pool will run any closure you send to it. With the exception that this
23+
pool have a fixed number of threads running.
24+
25+
```php
26+
$loop = Factory::create();
27+
28+
$finite = new Limited(
29+
new Infinite($loop, new EventLoopBridge($loop), 1), // Another pool, preferably an inifinite pool
30+
100 // The amount of threads to start and keep running
31+
);
32+
$time = time();
33+
$finite->run(function (int $time): int {
34+
return $time;
35+
}, [$time])->then(function (int $time): void {
36+
echo 'Unix timestamp: ', $time, PHP_EOL;
37+
})->done();
38+
```
39+
2040
## License ##
2141

22-
Copyright 2019 [Cees-Jan Kiewiet](http://wyrihaximus.net/)
42+
Copyright 2020 [Cees-Jan Kiewiet](http://wyrihaximus.net/)
2343

2444
Permission is hereby granted, free of charge, to any person
2545
obtaining a copy of this software and associated documentation

examples/sleep.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use React\EventLoop\Factory;
55
use ReactParallel\EventLoop\EventLoopBridge;
6+
use ReactParallel\Pool\Infinite\Infinite;
67
use ReactParallel\Pool\Limited\Limited;
78
use WyriHaximus\React\Parallel\Finite;
89
use function React\Promise\all;
@@ -12,7 +13,7 @@
1213

1314
$loop = Factory::create();
1415

15-
$finite = Limited::create($loop, new EventLoopBridge($loop), 100);
16+
$finite = new Limited(new Infinite($loop, new EventLoopBridge($loop), 1), 100);
1617

1718
$timer = $loop->addPeriodicTimer(1, function () use ($finite) {
1819
var_export(iteratorOrArrayToArray($finite->info()));

examples/versions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use PackageVersions\Versions;
55
use React\EventLoop\Factory;
66
use ReactParallel\EventLoop\EventLoopBridge;
7+
use ReactParallel\Pool\Infinite\Infinite;
78
use ReactParallel\Pool\Limited\Limited;
89
use WyriHaximus\React\Parallel\Finite;
910
use function WyriHaximus\iteratorOrArrayToArray;
@@ -12,7 +13,7 @@
1213

1314
$loop = Factory::create();
1415

15-
$finite = Limited::create($loop, new EventLoopBridge($loop), 2);
16+
$finite = new Limited(new Infinite($loop, new EventLoopBridge($loop), 1), 2);
1617

1718
$timer = $loop->addPeriodicTimer(1, function () use ($finite) {
1819
var_export(iteratorOrArrayToArray($finite->info()));

src/Limited.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@
55
namespace ReactParallel\Pool\Limited;
66

77
use Closure;
8-
use React\EventLoop\LoopInterface;
98
use React\Promise\Promise;
109
use React\Promise\PromiseInterface;
1110
use ReactParallel\Contracts\ClosedException;
1211
use ReactParallel\Contracts\GroupInterface;
1312
use ReactParallel\Contracts\LowLevelPoolInterface;
1413
use ReactParallel\Contracts\PoolInterface;
15-
use ReactParallel\EventLoop\EventLoopBridge;
16-
use ReactParallel\Pool\Infinite\Infinite;
1714
use SplQueue;
1815
use WyriHaximus\PoolInfo\Info;
1916

@@ -35,17 +32,7 @@ final class Limited implements PoolInterface
3532

3633
private bool $closed = false;
3734

38-
public static function create(LoopInterface $loop, EventLoopBridge $eventLoopBridge, int $threadCount): self
39-
{
40-
return new self(new Infinite($loop, $eventLoopBridge, 1), $threadCount);
41-
}
42-
43-
public static function createWithPool(PoolInterface $pool, int $threadCount): self
44-
{
45-
return new self($pool, $threadCount);
46-
}
47-
48-
private function __construct(PoolInterface $pool, int $threadCount)
35+
public function __construct(PoolInterface $pool, int $threadCount)
4936
{
5037
$this->pool = $pool;
5138
$this->threadCount = $threadCount;

tests/LimitedTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use React\EventLoop\LoopInterface;
77
use ReactParallel\Contracts\PoolInterface;
88
use ReactParallel\EventLoop\EventLoopBridge;
9+
use ReactParallel\Pool\Infinite\Infinite;
910
use ReactParallel\Pool\Limited\Limited;
1011
use ReactParallel\Tests\AbstractPoolTest;
1112
use WyriHaximus\PoolInfo\PoolInfoInterface;
@@ -21,11 +22,11 @@ final class LimitedTest extends AbstractPoolTest
2122
private function poolFactory(): PoolInfoInterface
2223
{
2324
$loop = Factory::create();
24-
return Limited::create($loop, new EventLoopBridge($loop), 5);
25+
return new Limited(new Infinite($loop, new EventLoopBridge($loop), 1), 5);
2526
}
2627

2728
protected function createPool(LoopInterface $loop): PoolInterface
2829
{
29-
return Limited::create($loop, new EventLoopBridge($loop), 5);
30+
return new Limited(new Infinite($loop, new EventLoopBridge($loop), 1), 5);
3031
}
3132
}

tests/LimitedWithPoolTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ final class LimitedWithPoolTest extends AbstractPoolTest
2222
private function poolFactory(): PoolInfoInterface
2323
{
2424
$loop = Factory::create();
25-
return Limited::createWithPool(new Infinite($loop, new EventLoopBridge($loop), 0.2), 5);
25+
return new Limited(new Infinite($loop, new EventLoopBridge($loop), 1), 5);
2626
}
2727

2828
protected function createPool(LoopInterface $loop): PoolInterface
2929
{
30-
return Limited::createWithPool(new Infinite($loop, new EventLoopBridge($loop), 0.2), 5);
30+
return new Limited(new Infinite($loop, new EventLoopBridge($loop), 1), 5);
3131
}
3232
}

0 commit comments

Comments
 (0)