public function update(Server $server) : Promise { switch ($server->state()) { case Server::STARTED: $this->watcherId = \Amp\repeat([$this, "updateTime"], 1000); $this->updateTime(); break; case Server::STOPPED: \Amp\cancel($this->watcherId); $this->watcherId = null; break; } return new Success(); }
public function update(Server $server) : Promise { if ($server->state() === Server::STARTED) { if ($this->callable) { $callable = $this->callable; $return = $callable($server); if ($return instanceof Promise) { return $return; } else { return new Success(); } } } return new Success(); }
/** * Receive notifications from the server when it starts/stops * * @param Server $server * @return \Amp\Promise */ public function update(Server $server) : amp\Promise { switch ($server->state()) { case Server::STARTING: $this->loadMimeFileTypes(__DIR__ . "/../etc/mime"); break; case Server::STARTED: $this->debug = $server->getOption("debug"); amp\enable($this->cacheWatcher); break; case Server::STOPPED: amp\disable($this->cacheWatcher); $this->cache = []; $this->cacheTimeouts = []; $this->cacheEntryCount = 0; $this->bufferedFileCount = 0; break; } return new amp\Success(); }
/** * React to server state changes * * Here we generate our dispatcher when the server notifies us that it is * ready to start (Server::STARTING). * * @param Server $server * @return \Amp\Promise */ public function update(Server $server) : Promise { switch ($this->state = $server->state()) { case Server::STOPPED: $this->routeDispatcher = null; break; case Server::STARTING: if (empty($this->routes)) { return new Failure(new \DomainException("Router start failure: no routes registered")); } $this->routeDispatcher = simpleDispatcher(function ($rc) use($server) { $this->buildRouter($rc, $server); }); break; } return new Success(); }
public function update(Server $server) : Promise { if ($server->state() === Server::STOPPING) { $this->isStopping = true; } return new Success(); }