public function testThen() { $results = array(); $doneCallback = function ($result) use(&$results) { $results[] = $result; }; $reasons = array(); $failCallback = function ($reason) use(&$reasons) { $reasons[] = $reason; }; $updates = array(); $progressCallback = function ($update) use(&$updates) { $updates[] = $update; }; $promise = new Promise(); $promise->then($doneCallback); $promise->then($doneCallback, $failCallback); $promise->then($doneCallback, $failCallback, $progressCallback); $promise->resolve('foo'); $promise->reject('bar'); $promise->notify('foobar'); $this->assertCount(3, $results); $this->assertSame(array('foo', 'foo', 'foo'), $results); $this->assertCount(2, $reasons); $this->assertSame(array('bar', 'bar'), $reasons); $this->assertCount(1, $updates); $this->assertSame(array('foobar'), $updates); }
/** * Starts a process and returns a promise * * @param Process $process * * @return Promise */ public function start(Process $process) { $promise = new Promise(); $process->start(function ($type, $update) use($promise) { $promise->notify($update, $type); }); $this->promises[] = $promise; $this->prosesses[] = $process; return $promise; }