loop = $loop; $this->frames = $frames; $this->count = \count($frames); $this->delay = ((int) (2 * 100 / $this->count)) / 100; } protected function getNextFrame() { $first = $this->frame === -1; $this->frame++; if ($this->frame >= $this->count) { $this->frame = 0; } return $this->frames[$this->frame]; } public function spinWhile(ExtendedPromiseInterface $promise, callable $renderer) { $next = function () use ($renderer) { $renderer($this->getNextFrame()); }; $spinTimer = $this->loop->addPeriodicTimer($this->delay, $next); $deferred = new Deferred(function () use ($spinTimer) { $this->loop->cancelTimer($spinTimer); }); $this->loop->futureTick($next); $wait = $deferred->promise(); $cancel = function () use ($wait) { $wait->cancel(); }; $promise->otherwise($cancel)->then($cancel); return $promise; } }