Implementing ThreadPoolOperator
We're going to write a universal operator that receives jobs represented by Thread class instances from its source Observable. Then, it'll submit them to an internal instance of the Pool class that we saw in the previous chapter.
In fact, this example with pthreads is going to be entirely built on all the things we've learned in the previous chapter, so we won't recap them here.
Note
This example is also going to use PHP7 syntax in some situations since pthreads v3 works only with PHP7 anyway.
For this operator, well internally use an event loop. In RxPHP, this means we'll use the StreamSelectLoop class wrapped with a Scheduler class. Let's see the source code for ThreadPoolOperator and then talk about why it's implemented like this:
// ThreadPoolOperator.php
class ThreadPoolOperator implements OperatorInterface {
private $pool;
public function __construct($num = 4,
$workerClass = Worker::class, $workerArgs =...