Exemple #1
0
 public function testWaterfallWithTasks()
 {
     $loop = new \React\EventLoop\StreamSelectLoop();
     $tasks = array(function ($callback, $errback) use($loop) {
         $loop->addTimer(0.05, function () use($callback) {
             $callback('foo');
         });
     }, function ($foo, $callback, $errback) use($loop) {
         $loop->addTimer(0.05, function () use($callback, $foo) {
             $callback($foo . 'bar');
         });
     }, function ($bar, $callback, $errback) use($loop) {
         $loop->addTimer(0.05, function () use($callback, $bar) {
             $callback($bar . 'baz');
         });
     });
     $callback = $this->createCallableMock($this->once(), 'foobarbaz');
     $errback = $this->createCallableMock($this->never());
     Util::waterfall($tasks, $callback, $errback);
     $timer = new Timer($this);
     $timer->start();
     $loop->run();
     $timer->stop();
     $timer->assertInRange(0.15, 0.3);
 }
Exemple #2
0
 public function testParallelWithTasks()
 {
     $loop = new \React\EventLoop\StreamSelectLoop();
     $tasks = array(function ($callback, $errback) use($loop) {
         $loop->addTimer(0.1, function () use($callback) {
             $callback('foo');
         });
     }, function ($callback, $errback) use($loop) {
         $loop->addTimer(0.1, function () use($callback) {
             $callback('bar');
         });
     });
     $callback = $this->createCallableMock($this->once(), array('foo', 'bar'));
     $errback = $this->createCallableMock($this->never());
     Util::parallel($tasks, $callback, $errback);
     $timer = new Timer($this);
     $timer->start();
     $loop->run();
     $timer->stop();
     $timer->assertInRange(0.1, 0.2);
 }