Skip to content

Commit

Permalink
amphp#64 some progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekstazi committed Dec 11, 2018
1 parent 866fbf4 commit 0e060da
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions lib/Context/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ public function kill()
} finally {
$this->close();
}
$this->oid = 0;
}
}

Expand Down Expand Up @@ -249,7 +248,7 @@ public function join(): Promise
Loop::disable($this->watcher);
$this->close();
}
$this->oid = 0;

return $response->getResult();
});
}
Expand Down
6 changes: 4 additions & 2 deletions lib/Worker/TaskWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ public function restart($force = false): Promise
{
return call(function () use ($force) {
if ($force) {
$this->context->kill();
$this->kill();
} else {
yield $this->shutdown();
}
yield $this->context->start();

$context = yield $this->context->restart($force);
return new static($context);
});
}
}
2 changes: 1 addition & 1 deletion lib/Worker/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function kill();
/**
* Restart worker.
* @param bool $force Whether for cancel current task or wait it finished
* @return Promise
* @return Promise<Worker> New created worker
*/
public function restart($force = false): Promise;
}
10 changes: 6 additions & 4 deletions test/Worker/AbstractWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,25 +267,27 @@ public function run(Environment $environment)
public function testRestart()
{
Loop::run(function () {
$worker = $this->createWorker();
$worker = $original = $this->createWorker();
for ($i=0; $i<=1; $i++) {
$returnValue = yield $worker->enqueue(new TestTask(42));
$this->assertEquals(42, $returnValue);

yield $worker->restart();
$worker = yield $worker->restart();
$this->assertNotEquals($worker, $original);
}
});
}

public function testForceRestart()
{
Loop::run(function () {
$worker = $this->createWorker();
$worker = $original = $this->createWorker();
for ($i=0; $i<=1; $i++) {
$returnValue = yield $worker->enqueue(new TestTask(42));
$this->assertEquals(42, $returnValue);

yield $worker->restart(true);
$worker = yield $worker->restart(true);
$this->assertNotEquals($worker, $original);
}
});
}
Expand Down

0 comments on commit 0e060da

Please sign in to comment.