mirror of
https://github.com/danog/amp.git
synced 2024-11-27 04:24:42 +01:00
Add tests for Promisor::update()
This commit is contained in:
parent
99e38762a7
commit
b1a5d113a8
@ -88,4 +88,27 @@ class FutureTest extends \PHPUnit_Framework_TestCase {
|
||||
yield $promisor->promise();
|
||||
});
|
||||
}
|
||||
|
||||
public function testUpdate() {
|
||||
$updatable = 0;
|
||||
(new NativeReactor)->run(function() use (&$updatable) {
|
||||
$i = 0;
|
||||
$promisor = new Future;
|
||||
$updater = function($reactor, $watcherId) use ($promisor, &$i) {
|
||||
$promisor->update(++$i);
|
||||
if ($i === 3) {
|
||||
$reactor->cancel($watcherId);
|
||||
// reactor run loop should now be able to exit
|
||||
}
|
||||
};
|
||||
$promise = $promisor->promise();
|
||||
|
||||
$promise->watch(function($updateData) use (&$updatable) {
|
||||
$updatable += $updateData;
|
||||
});
|
||||
yield 'repeat' => [$updater, $msDelay = 10];
|
||||
});
|
||||
|
||||
$this->assertSame(6, $updatable);
|
||||
}
|
||||
}
|
||||
|
@ -72,4 +72,26 @@ class PrivateFutureTest extends \PHPUnit_Framework_TestCase {
|
||||
yield $promisor->promise();
|
||||
});
|
||||
}
|
||||
|
||||
public function testUpdate() {
|
||||
$updatable = 0;
|
||||
(new NativeReactor)->run(function() use (&$updatable) {
|
||||
$i = 0;
|
||||
$promisor = new PrivateFuture;
|
||||
$updater = function($reactor, $watcherId) use ($promisor, &$i) {
|
||||
$promisor->update(++$i);
|
||||
if ($i === 3) {
|
||||
$reactor->cancel($watcherId);
|
||||
// reactor run loop should now be able to exit
|
||||
}
|
||||
};
|
||||
$promise = $promisor->promise();
|
||||
$promise->watch(function($updateData) use (&$updatable) {
|
||||
$updatable += $updateData;
|
||||
});
|
||||
yield 'repeat' => [$updater, $msDelay = 10];
|
||||
});
|
||||
|
||||
$this->assertSame(6, $updatable);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user