상속: implements Rx\SchedulerInterface
예제 #1
0
 /**
  * @test
  */
 public function eventloop_schedule_recursive()
 {
     $loop = Factory::create();
     $scheduler = new EventLoopScheduler($loop);
     $actionCalled = false;
     $count = 0;
     $action = function ($reschedule) use(&$actionCalled, &$count) {
         $actionCalled = true;
         $count++;
         if ($count < 5) {
             $reschedule();
         }
     };
     $disposable = $scheduler->scheduleRecursive($action);
     $this->assertInstanceOf('Rx\\DisposableInterface', $disposable);
     $this->assertFalse($actionCalled);
     $this->assertEquals(0, $count);
     $loop->tick();
     $this->assertEquals(1, $count);
     $loop->tick();
     $this->assertEquals(2, $count);
     $loop->tick();
     $this->assertEquals(3, $count);
     $loop->tick();
     $this->assertEquals(4, $count);
     $loop->tick();
     $this->assertEquals(5, $count);
     $loop->tick();
     $this->assertTrue($actionCalled);
     $this->assertEquals(5, $count);
 }
예제 #2
0
 public function testSchedulerWorkedWithScheduledEventOutsideItself()
 {
     $loop = Factory::create();
     $scheduler = new EventLoopScheduler($loop);
     $scheduler->start();
     $start = microtime(true);
     $called = null;
     $loop->addTimer(0.1, function () use($scheduler, &$called) {
         $scheduler->schedule(function () use(&$called) {
             $called = microtime(true);
         }, 100);
     });
     $loop->run();
     $this->assertEquals(0.2, $called - $start, '', 0.02);
 }
예제 #3
0
 /**
  * @test
  */
 public function now_returns_the_time()
 {
     $loop = Factory::create();
     $scheduler = new EventLoopScheduler($loop);
     $this->assertTrue(abs(time() - $scheduler->now()) < 1, "time difference is less than or equal to 1");
 }
예제 #4
0
파일: flatmap.php 프로젝트: domraider/rxnet
use Rxnet\Thread\RxThread;
use Rxnet\Zmq\RxZmq;
use Rxnet\Zmq\SocketWrapper;
require __DIR__ . "/../vendor/autoload.php";
function asString($value)
{
    if (is_array($value)) {
        return json_encode($value);
    }
    return (string) $value;
}
$createStdoutObserver = function ($prefix = '') {
    return new Rx\Observer\CallbackObserver(function ($value) use($prefix) {
        echo $prefix . "Next value: " . asString($value) . " : " . memory_get_usage(true) . "\n";
    }, function ($error) use($prefix) {
        echo $prefix . "Exception: " . $error->getMessage() . "\n";
    }, function () use($prefix) {
        echo $prefix . "Complete!\n";
    });
};
$loop = Factory::create();
$scheduler = new EventLoopScheduler($loop);
$i = 0;
$mem = function () use(&$i) {
    echo memory_get_usage(true) . "\n";
};
$scheduler->schedulePeriodic($mem, 10 * 1000, 10 * 1000);
$scheduler->schedulePeriodic(function () use(&$i) {
    $i++;
}, 0, 10);
$loop->run();