/** * {@inheritdoc} */ public function stop() { $this->loop->stop(\Ev::BREAK_ONE); parent::stop(); }
function testStop() { $check = 0; $loop = new Loop(); $loop->setTimeout(function () use(&$check) { $check++; }, 200); $loop->nextTick(function () use($loop) { $loop->stop(); }); $loop->run(); $this->assertEquals(0, $check); }
/** * {@inheritdoc} */ public function stop() { $this->loop->stop(); parent::stop(); }
/** * Runs the event loop until the promise is resolved. Should not be called within a running event loop. * * @param \Interop\Async\Promise $promise * * @return mixed Promise success value. * * @throws \Throwable Promise failure reason. */ function wait(Promise $promise) { $resolved = false; Loop::execute(function () use(&$resolved, &$value, &$exception, $promise) { $promise->when(function ($e, $v) use(&$resolved, &$value, &$exception) { Loop::stop(); $resolved = true; $exception = $e; $value = $v; }); }, Loop::get()); if (!$resolved) { throw new \Error("Loop emptied without resolving promise"); } if ($exception) { throw $exception; } return $value; }