/** * @test */ public function gettersAndSettersWork() { $this->task->setId(3); $this->assertEquals(3, $this->task->getId()); $this->assertEquals(-1, $this->task->getExpiresIn()); $this->assertFalse($this->task->hasExpired()); $this->assertTrue($this->task->shouldExpire(time())); $this->assertTrue($this->task->hasExpired()); }
/** * @inheritdoc * * @return bool */ public function tick() { $this->server->tick(); if ($this->manager->tick()) { return true; } $this->server->tick(); if (empty($this->waiting)) { return false; } $next = array_shift($this->waiting); if ($next["type"] === "parallel") { $client = $this->getClient(); $tasks = $next["tasks"]; $tasks = array_map(function ($task) use($client) { if ($task instanceof Task) { return $task; } if ($task instanceof Closure) { $task = new ProcessCallbackTask($task); } if ($task instanceof Task) { return new DoormanTask($task, $client); } return $task; }, $tasks); $tasks = array_filter($tasks, function ($task) { return $task instanceof Task; }); $this->manager->addTaskGroup($tasks); } if ($next["type"] === "synchronous") { foreach ($next["tasks"] as $task) { if ($task instanceof Task) { $handler = $task->getHandler(); $object = new $handler(); if ($object instanceof Handler) { $object = new DoormanHandler($object); $object->handle($task); } } } } return true; }