1
0
mirror of https://github.com/danog/amp.git synced 2024-12-02 09:27:46 +01:00

Rename Promise::when to Promise::onResolve, resolves #77

This commit is contained in:
Niklas Keller 2017-03-21 17:23:37 +01:00
parent 3b6ca19dfe
commit ce269fa516
39 changed files with 202 additions and 202 deletions

View File

@ -14,7 +14,7 @@ The basic unit of concurrency in Amp applications is the `Amp\Promise`. These ob
```php ```php
interface Promise { interface Promise {
public function when(callable $onResolve); public function onResolve(callable $onResolve);
} }
``` ```
@ -23,15 +23,15 @@ In its simplest form the `Amp\Promise` aggregates callbacks for dealing with com
| Method | Callback Signature | | Method | Callback Signature |
| --------- | ----------------------------------------------------------| | --------- | ----------------------------------------------------------|
| when | `function ($error = null, $result = null)` | | onResolve | `function ($error = null, $result = null)` |
`Amp\Promise::when()` accepts an error-first callback. This callback is responsible for reacting to the eventual result of the computation represented by the promise placeholder. For example: `Amp\Promise::onResolve()` accepts an error-first callback. This callback is responsible for reacting to the eventual result of the computation represented by the promise placeholder. For example:
```php ```php
<?php <?php
$promise = someFunctionThatReturnsAPromise(); $promise = someFunctionThatReturnsAPromise();
$promise->when(function (Throwable $error = null, $result = null) { $promise->onResolve(function (Throwable $error = null, $result = null) {
if ($error) { if ($error) {
printf( printf(
"Something went wrong:\n%s\n", "Something went wrong:\n%s\n",
@ -66,11 +66,11 @@ Returns the corresponding `Promise` instance. `Deferred` and `Promise` are separ
#### `resolve()` #### `resolve()`
Resolves the promise with the first parameter as value, otherwise `null`. If a `Amp\Promise` is passed, the resolution will wait until the passed promise has been resolved. Invokes all registered `Promise::when()` callbacks. Resolves the promise with the first parameter as value, otherwise `null`. If a `Amp\Promise` is passed, the resolution will wait until the passed promise has been resolved. Invokes all registered `Promise::onResolve()` callbacks.
#### `fail()` #### `fail()`
Makes the promise fail. Invokes all registered `Promise::when()` callbacks with the passed `Throwable` as `$error` argument. Makes the promise fail. Invokes all registered `Promise::onResolve()` callbacks with the passed `Throwable` as `$error` argument.
Here's a simple example of an async value producer `asyncMultiply()` creating a deferred and returning the associated promise to its API consumer. Here's a simple example of an async value producer `asyncMultiply()` creating a deferred and returning the associated promise to its API consumer.

View File

@ -19,7 +19,7 @@ Loop::run(function () {
return new Pause(500); // Artificial back-pressure on stream. return new Pause(500); // Artificial back-pressure on stream.
}); });
$stream->when(function (Throwable $exception = null, $value) { $stream->onResolve(function (Throwable $exception = null, $value) {
if ($exception) { if ($exception) {
printf("Stream failed: %s\n", $exception->getMessage()); printf("Stream failed: %s\n", $exception->getMessage());
return; return;

View File

@ -25,7 +25,7 @@ final class Coroutine implements Promise {
private $generator; private $generator;
/** @var callable(\Throwable|null $exception, mixed $value): void */ /** @var callable(\Throwable|null $exception, mixed $value): void */
private $when; private $onResolve;
/** @var int */ /** @var int */
private $depth = 0; private $depth = 0;
@ -40,10 +40,10 @@ final class Coroutine implements Promise {
* @param \Throwable|null $exception Exception to be thrown into the generator. * @param \Throwable|null $exception Exception to be thrown into the generator.
* @param mixed $value Value to be sent into the generator. * @param mixed $value Value to be sent into the generator.
*/ */
$this->when = function ($exception, $value) { $this->onResolve = function ($exception, $value) {
if ($this->depth > self::MAX_CONTINUATION_DEPTH) { // Defer continuation to avoid blowing up call stack. if ($this->depth > self::MAX_CONTINUATION_DEPTH) { // Defer continuation to avoid blowing up call stack.
Loop::defer(function () use ($exception, $value) { Loop::defer(function () use ($exception, $value) {
($this->when)($exception, $value); ($this->onResolve)($exception, $value);
}); });
return; return;
} }
@ -67,7 +67,7 @@ final class Coroutine implements Promise {
} }
++$this->depth; ++$this->depth;
$yielded->when($this->when); $yielded->onResolve($this->onResolve);
--$this->depth; --$this->depth;
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->dispose($exception); $this->dispose($exception);
@ -87,7 +87,7 @@ final class Coroutine implements Promise {
} }
++$this->depth; ++$this->depth;
$yielded->when($this->when); $yielded->onResolve($this->onResolve);
--$this->depth; --$this->depth;
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
$this->dispose($exception); $this->dispose($exception);

View File

@ -19,7 +19,7 @@ final class Failure implements Stream {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function when(callable $onResolved) { public function onResolve(callable $onResolved) {
try { try {
$onResolved($this->exception, null); $onResolved($this->exception, null);
} catch (\Throwable $exception) { } catch (\Throwable $exception) {

View File

@ -21,16 +21,16 @@ trait Placeholder {
/** @var mixed */ /** @var mixed */
private $result; private $result;
/** @var callable|\Amp\Internal\WhenQueue|null */ /** @var callable|\Amp\Internal\ResolutionQueue|null */
private $onResolved; private $onResolved;
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function when(callable $onResolved) { public function onResolve(callable $onResolved) {
if ($this->resolved) { if ($this->resolved) {
if ($this->result instanceof Promise) { if ($this->result instanceof Promise) {
$this->result->when($onResolved); $this->result->onResolve($onResolved);
return; return;
} }
@ -49,8 +49,8 @@ trait Placeholder {
return; return;
} }
if (!$this->onResolved instanceof WhenQueue) { if (!$this->onResolved instanceof ResolutionQueue) {
$this->onResolved = new WhenQueue($this->onResolved); $this->onResolved = new ResolutionQueue($this->onResolved);
} }
$this->onResolved->push($onResolved); $this->onResolved->push($onResolved);
@ -81,7 +81,7 @@ trait Placeholder {
$this->onResolved = null; $this->onResolved = null;
if ($this->result instanceof Promise) { if ($this->result instanceof Promise) {
$this->result->when($onResolved); $this->result->onResolve($onResolved);
return; return;
} }

View File

@ -57,7 +57,7 @@ trait Producer {
if ($value instanceof Promise) { if ($value instanceof Promise) {
$deferred = new Deferred; $deferred = new Deferred;
$value->when(function ($e, $v) use ($deferred) { $value->onResolve(function ($e, $v) use ($deferred) {
if ($this->resolved) { if ($this->resolved) {
$deferred->fail( $deferred->fail(
new \Error("The stream was resolved before the promise result could be emitted") new \Error("The stream was resolved before the promise result could be emitted")
@ -113,7 +113,7 @@ trait Producer {
}; };
foreach ($promises as $promise) { foreach ($promises as $promise) {
$promise->when($f); $promise->onResolve($f);
} }
return $deferred->promise(); return $deferred->promise();

View File

@ -9,7 +9,7 @@ use Amp\Loop;
* *
* @internal * @internal
*/ */
class WhenQueue { class ResolutionQueue {
/** @var callable[] */ /** @var callable[] */
private $queue = []; private $queue = [];

View File

@ -5,9 +5,9 @@ namespace Amp;
use React\Promise\PromiseInterface as ReactPromise; use React\Promise\PromiseInterface as ReactPromise;
/** /**
* Creates a promise that calls $promisor only when the result of the promise is requested (i.e. when() is called on * Creates a promise that calls $promisor only when the result of the promise is requested (i.e. onResolve() is called
* the promise). $promisor can return a promise or any value. If $promisor throws an exception, the promise fails with * on the promise). $promisor can return a promise or any value. If $promisor throws an exception, the promise fails
* that exception. * with that exception.
*/ */
class LazyPromise implements Promise { class LazyPromise implements Promise {
/** @var callable|null */ /** @var callable|null */
@ -26,7 +26,7 @@ class LazyPromise implements Promise {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function when(callable $onResolved) { public function onResolve(callable $onResolved) {
if ($this->promise === null) { if ($this->promise === null) {
$provider = $this->promisor; $provider = $this->promisor;
$this->promisor = null; $this->promisor = null;
@ -46,6 +46,6 @@ class LazyPromise implements Promise {
} }
} }
$this->promise->when($onResolved); $this->promise->onResolve($onResolved);
} }
} }

View File

@ -68,7 +68,7 @@ class Listener implements Iterator {
$result = &$this->result; $result = &$this->result;
$error = &$this->exception; $error = &$this->exception;
$this->stream->when(static function ($exception, $value) use (&$waiting, &$result, &$error, &$resolved) { $this->stream->onResolve(static function ($exception, $value) use (&$waiting, &$result, &$error, &$resolved) {
$resolved = true; $resolved = true;
if ($exception) { if ($exception) {

View File

@ -43,7 +43,7 @@ class Message implements Iterator, Promise {
public function __construct(Stream $stream) { public function __construct(Stream $stream) {
$this->listener = new Listener($stream); $this->listener = new Listener($stream);
$stream->when(function ($exception, $value) { $stream->onResolve(function ($exception, $value) {
if ($exception) { if ($exception) {
$this->fail($exception); $this->fail($exception);
return; return;

View File

@ -19,7 +19,7 @@ final class Producer implements Stream {
Loop::defer(function () use ($result) { Loop::defer(function () use ($result) {
$coroutine = new Coroutine($result); $coroutine = new Coroutine($result);
$coroutine->when(function ($exception, $value) { $coroutine->onResolve(function ($exception, $value) {
if ($this->resolved) { if ($this->resolved) {
return; return;
} }

View File

@ -16,5 +16,5 @@ interface Promise {
* *
* @return mixed Return type and value are unspecified. * @return mixed Return type and value are unspecified.
*/ */
public function when(callable $onResolved); public function onResolve(callable $onResolved);
} }

View File

@ -28,7 +28,7 @@ final class Success implements Stream {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function when(callable $onResolved) { public function onResolve(callable $onResolved) {
try { try {
$onResolved(null, $this->value); $onResolved(null, $this->value);
} catch (\Throwable $exception) { } catch (\Throwable $exception) {

View File

@ -158,7 +158,7 @@ namespace Amp\Promise {
} }
} }
$promise->when(function ($exception) { $promise->onResolve(function ($exception) {
if ($exception) { if ($exception) {
throw $exception; throw $exception;
} }
@ -186,7 +186,7 @@ namespace Amp\Promise {
$resolved = false; $resolved = false;
Loop::run(function () use (&$resolved, &$value, &$exception, $promise) { Loop::run(function () use (&$resolved, &$value, &$exception, $promise) {
$promise->when(function ($e, $v) use (&$resolved, &$value, &$exception) { $promise->onResolve(function ($e, $v) use (&$resolved, &$value, &$exception) {
Loop::stop(); Loop::stop();
$resolved = true; $resolved = true;
$exception = $e; $exception = $e;
@ -226,7 +226,7 @@ namespace Amp\Promise {
$deferred = new Deferred; $deferred = new Deferred;
$promise->when(function ($exception, $value) use ($deferred, $functor) { $promise->onResolve(function ($exception, $value) use ($deferred, $functor) {
if ($exception) { if ($exception) {
$deferred->fail($exception); $deferred->fail($exception);
return; return;
@ -263,7 +263,7 @@ namespace Amp\Promise {
$deferred = new Deferred; $deferred = new Deferred;
$promise->when(function ($exception, $value) use ($deferred, $className, $functor) { $promise->onResolve(function ($exception, $value) use ($deferred, $className, $functor) {
if (!$exception) { if (!$exception) {
$deferred->resolve($value); $deferred->resolve($value);
return; return;
@ -317,7 +317,7 @@ namespace Amp\Promise {
}); });
Loop::unreference($watcher); Loop::unreference($watcher);
$promise->when(function () use (&$resolved, $promise, $deferred, $watcher) { $promise->onResolve(function () use (&$resolved, $promise, $deferred, $watcher) {
Loop::cancel($watcher); Loop::cancel($watcher);
if ($resolved) { if ($resolved) {
@ -388,7 +388,7 @@ namespace Amp\Promise {
throw new UnionTypeError([Promise::class, ReactPromise::class], $promise); throw new UnionTypeError([Promise::class, ReactPromise::class], $promise);
} }
$promise->when(function ($error, $value) use (&$pending, &$errors, &$values, $key, $deferred) { $promise->onResolve(function ($error, $value) use (&$pending, &$errors, &$values, $key, $deferred) {
if ($error) { if ($error) {
$errors[$key] = $error; $errors[$key] = $error;
} else { } else {
@ -432,7 +432,7 @@ namespace Amp\Promise {
throw new UnionTypeError([Promise::class, ReactPromise::class], $promise); throw new UnionTypeError([Promise::class, ReactPromise::class], $promise);
} }
$promise->when(function ($exception, $value) use (&$values, &$pending, &$resolved, $key, $deferred) { $promise->onResolve(function ($exception, $value) use (&$values, &$pending, &$resolved, $key, $deferred) {
if ($resolved) { if ($resolved) {
return; return;
} }
@ -480,7 +480,7 @@ namespace Amp\Promise {
throw new UnionTypeError([Promise::class, ReactPromise::class], $promise); throw new UnionTypeError([Promise::class, ReactPromise::class], $promise);
} }
$promise->when(function ($exception, $value) use (&$exceptions, &$pending, &$resolved, $key, $deferred) { $promise->onResolve(function ($exception, $value) use (&$exceptions, &$pending, &$resolved, $key, $deferred) {
if ($resolved) { if ($resolved) {
return; return;
} }
@ -528,7 +528,7 @@ namespace Amp\Promise {
throw new UnionTypeError([Promise::class, ReactPromise::class], $promise); throw new UnionTypeError([Promise::class, ReactPromise::class], $promise);
} }
$promise->when(function ($exception, $value) use (&$values, &$exceptions, &$pending, $key, $deferred) { $promise->onResolve(function ($exception, $value) use (&$values, &$exceptions, &$pending, $key, $deferred) {
if ($exception) { if ($exception) {
$exceptions[$key] = $exception; $exceptions[$key] = $exception;
} else { } else {
@ -668,7 +668,7 @@ namespace Amp\Stream {
}); });
} }
Promise\all($streams)->when(function ($exception, array $values = null) use (&$pending, $emitter) { Promise\all($streams)->onResolve(function ($exception, array $values = null) use (&$pending, $emitter) {
$pending = false; $pending = false;
if ($exception) { if ($exception) {
@ -730,7 +730,7 @@ namespace Amp\Stream {
$promise = Promise\all($previous); $promise = Promise\all($previous);
} }
$promise->when(function ($exception, array $values = null) use ($emitter) { $promise->onResolve(function ($exception, array $values = null) use ($emitter) {
if ($exception) { if ($exception) {
$emitter->fail($exception); $emitter->fail($exception);
return; return;

View File

@ -15,7 +15,7 @@ class PromiseMock {
} }
public function then(callable $onFulfilled = null, callable $onRejected = null) { public function then(callable $onFulfilled = null, callable $onRejected = null) {
$this->promise->when(function ($exception, $value) use ($onFulfilled, $onRejected) { $this->promise->onResolve(function ($exception, $value) use ($onFulfilled, $onRejected) {
if ($exception) { if ($exception) {
if ($onRejected) { if ($onRejected) {
$onRejected($exception); $onRejected($exception);
@ -62,7 +62,7 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
$promise = Promise\adapt($promise); $promise = Promise\adapt($promise);
$promise->when(function ($exception, $value) use (&$result) { $promise->onResolve(function ($exception, $value) use (&$result) {
$result = $value; $result = $value;
}); });
@ -79,7 +79,7 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
$promise = Promise\adapt($promise); $promise = Promise\adapt($promise);
$promise->when(function ($exception, $value) use (&$reason) { $promise->onResolve(function ($exception, $value) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });

View File

@ -13,7 +13,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\all([])->when($callback); Promise\all([])->onResolve($callback);
$this->assertSame([], $result); $this->assertSame([], $result);
} }
@ -25,7 +25,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\all($promises)->when($callback); Promise\all($promises)->onResolve($callback);
$this->assertSame([1, 2, 3], $result); $this->assertSame([1, 2, 3], $result);
} }
@ -42,7 +42,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\all($promises)->when($callback); Promise\all($promises)->onResolve($callback);
}); });
$this->assertEquals([1, 2, 3], $result); $this->assertEquals([1, 2, 3], $result);
@ -62,7 +62,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\all($promises)->when($callback); Promise\all($promises)->onResolve($callback);
}); });
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);

View File

@ -14,7 +14,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\any([])->when($callback); Promise\any([])->onResolve($callback);
$this->assertSame([[], []], $result); $this->assertSame([[], []], $result);
} }
@ -26,7 +26,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\any($promises)->when($callback); Promise\any($promises)->onResolve($callback);
$this->assertEquals([[], [1, 2, 3]], $result); $this->assertEquals([[], [1, 2, 3]], $result);
} }
@ -39,7 +39,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\any($promises)->when($callback); Promise\any($promises)->onResolve($callback);
$this->assertEquals([[$exception, $exception, $exception], []], $result); $this->assertEquals([[$exception, $exception, $exception], []], $result);
} }
@ -52,7 +52,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\any($promises)->when($callback); Promise\any($promises)->onResolve($callback);
$this->assertEquals([[1 => $exception], [0 => 1, 2 => 3]], $result); $this->assertEquals([[1 => $exception], [0 => 1, 2 => 3]], $result);
} }
@ -69,7 +69,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\any($promises)->when($callback); Promise\any($promises)->onResolve($callback);
}); });
$this->assertEquals([[], [1, 2, 3]], $result); $this->assertEquals([[], [1, 2, 3]], $result);
@ -93,7 +93,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\any($promises)->when($callback); Promise\any($promises)->onResolve($callback);
}); });
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);

View File

@ -18,7 +18,7 @@ class CallTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -35,7 +35,7 @@ class CallTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -52,7 +52,7 @@ class CallTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -69,7 +69,7 @@ class CallTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -86,7 +86,7 @@ class CallTest extends TestCase {
$this->assertInstanceOf(Coroutine::class, $promise); $this->assertInstanceOf(Coroutine::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });

View File

@ -26,7 +26,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertFalse($invoked); $this->assertFalse($invoked);
$this->assertSame($value, $result); $this->assertSame($value, $result);
@ -51,7 +51,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertTrue($invoked); $this->assertTrue($invoked);
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);
@ -78,7 +78,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertTrue($invoked); $this->assertTrue($invoked);
$this->assertNotSame($exception, $reason); $this->assertNotSame($exception, $reason);
@ -105,7 +105,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertFalse($invoked); $this->assertFalse($invoked);
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);
@ -133,7 +133,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertTrue($invoked); $this->assertTrue($invoked);
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);

View File

@ -58,7 +58,7 @@ class ConcatTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertSame(\range(1, 6), $results); $this->assertSame(\range(1, 6), $results);

View File

@ -39,7 +39,7 @@ class CoroutineTest extends TestCase {
$this->assertNull($yielded); $this->assertNull($yielded);
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -159,7 +159,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -177,7 +177,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -198,7 +198,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -219,7 +219,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -241,7 +241,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -265,7 +265,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -284,7 +284,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -309,7 +309,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -335,7 +335,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -363,7 +363,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
}); });
@ -394,7 +394,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
}); });
@ -422,7 +422,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception) use (&$reason) { $coroutine->onResolve(function ($exception) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -446,7 +446,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function () use (&$invoked) { $coroutine->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
}); });
}); });
@ -475,7 +475,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function () use (&$invoked) { $coroutine->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
}); });
}); });
@ -495,7 +495,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$invoked = false; $invoked = false;
$coroutine->when(function () use (&$invoked) { $coroutine->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
}); });
@ -525,7 +525,7 @@ class CoroutineTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -548,7 +548,7 @@ class CoroutineTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -571,7 +571,7 @@ class CoroutineTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -593,7 +593,7 @@ class CoroutineTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -612,7 +612,7 @@ class CoroutineTest extends TestCase {
$this->assertInstanceOf(Promise::class, $promise); $this->assertInstanceOf(Promise::class, $promise);
$promise->when(function ($exception, $value) use (&$reason, &$result) { $promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -631,7 +631,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -656,7 +656,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -684,7 +684,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -705,7 +705,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -727,7 +727,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -748,7 +748,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -770,7 +770,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -792,7 +792,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });
@ -814,7 +814,7 @@ class CoroutineTest extends TestCase {
$coroutine = new Coroutine($generator()); $coroutine = new Coroutine($generator());
$coroutine->when(function ($exception, $value) use (&$reason, &$result) { $coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
$reason = $exception; $reason = $exception;
$result = $value; $result = $value;
}); });

View File

@ -26,7 +26,7 @@ class DeferredTest extends \PHPUnit\Framework\TestCase {
$promise = $this->deferred->promise(); $promise = $this->deferred->promise();
$invoked = false; $invoked = false;
$promise->when(function ($exception, $value) use (&$invoked, &$result) { $promise->onResolve(function ($exception, $value) use (&$invoked, &$result) {
$invoked = true; $invoked = true;
$result = $value; $result = $value;
}); });
@ -45,7 +45,7 @@ class DeferredTest extends \PHPUnit\Framework\TestCase {
$promise = $this->deferred->promise(); $promise = $this->deferred->promise();
$invoked = false; $invoked = false;
$promise->when(function ($exception, $value) use (&$invoked, &$result) { $promise->onResolve(function ($exception, $value) use (&$invoked, &$result) {
$invoked = true; $invoked = true;
$result = $exception; $result = $exception;
}); });

View File

@ -23,7 +23,7 @@ class FailureTest extends \PHPUnit\Framework\TestCase {
$success = new Failure($exception); $success = new Failure($exception);
$success->when($callback); $success->onResolve($callback);
$this->assertSame(1, $invoked); $this->assertSame(1, $invoked);
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);

View File

@ -46,7 +46,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
$results[] = $value; $results[] = $value;
}); });
$stream->when(function ($exception, $value) use (&$result) { $stream->onResolve(function ($exception, $value) use (&$result) {
$result = $value; $result = $value;
}); });
}); });
@ -80,7 +80,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);
@ -102,7 +102,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertFalse($invoked); $this->assertFalse($invoked);

View File

@ -26,7 +26,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\first($promises)->when($callback); Promise\first($promises)->onResolve($callback);
$this->assertSame(1, $result); $this->assertSame(1, $result);
} }
@ -39,7 +39,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
Promise\first($promises)->when($callback); Promise\first($promises)->onResolve($callback);
$this->assertInstanceOf(MultiReasonException::class, $reason); $this->assertInstanceOf(MultiReasonException::class, $reason);
$this->assertEquals([$exception, $exception, $exception], $reason->getReasons()); $this->assertEquals([$exception, $exception, $exception], $reason->getReasons());
@ -53,7 +53,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\first($promises)->when($callback); Promise\first($promises)->onResolve($callback);
$this->assertSame(3, $result); $this->assertSame(3, $result);
} }
@ -70,7 +70,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\first($promises)->when($callback); Promise\first($promises)->onResolve($callback);
}); });
$this->assertSame(3, $result); $this->assertSame(3, $result);

View File

@ -27,7 +27,7 @@ class LazyPromiseTest extends TestCase {
return $value; return $value;
}); });
$lazy->when(function ($exception, $value) use (&$result) { $lazy->onResolve(function ($exception, $value) use (&$result) {
$result = $value; $result = $value;
}); });
@ -44,7 +44,7 @@ class LazyPromiseTest extends TestCase {
return $promise; return $promise;
}); });
$lazy->when(function ($exception, $value) use (&$result) { $lazy->onResolve(function ($exception, $value) use (&$result) {
$result = $value; $result = $value;
}); });
@ -61,7 +61,7 @@ class LazyPromiseTest extends TestCase {
return $promise; return $promise;
}); });
$lazy->when(function ($exception, $value) use (&$reason) { $lazy->onResolve(function ($exception, $value) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -77,7 +77,7 @@ class LazyPromiseTest extends TestCase {
throw $exception; throw $exception;
}); });
$lazy->when(function ($exception, $value) use (&$reason) { $lazy->onResolve(function ($exception, $value) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });
@ -94,7 +94,7 @@ class LazyPromiseTest extends TestCase {
return $promise; return $promise;
}); });
$lazy->when(function ($exception, $value) use (&$result) { $lazy->onResolve(function ($exception, $value) use (&$result) {
$result = $value; $result = $value;
}); });
@ -111,7 +111,7 @@ class LazyPromiseTest extends TestCase {
return $promise; return $promise;
}); });
$lazy->when(function ($exception, $value) use (&$reason) { $lazy->onResolve(function ($exception, $value) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });

View File

@ -213,7 +213,7 @@ class ListenerTest extends \PHPUnit\Framework\TestCase {
unset($listener); unset($listener);
$invoked = false; $invoked = false;
$promise->when(function () use (&$invoked) { $promise->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
}); });
@ -231,7 +231,7 @@ class ListenerTest extends \PHPUnit\Framework\TestCase {
$promise = $emitter->emit(2); $promise = $emitter->emit(2);
$invoked = false; $invoked = false;
$promise->when(function () use (&$invoked) { $promise->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
}); });
@ -244,7 +244,7 @@ class ListenerTest extends \PHPUnit\Framework\TestCase {
$listener = new Listener($emitter->stream()); $listener = new Listener($emitter->stream());
$promise = $listener->advance(); $promise = $listener->advance();
$promise->when(function ($exception, $value) use (&$reason) { $promise->onResolve(function ($exception, $value) use (&$reason) {
$reason = $exception; $reason = $exception;
}); });

View File

@ -53,7 +53,7 @@ class MergeTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);

View File

@ -18,7 +18,7 @@ class PauseTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
}); });
$this->assertGreaterThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000); $this->assertGreaterThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000);
@ -39,7 +39,7 @@ class PauseTest extends \PHPUnit\Framework\TestCase {
$invoked = true; $invoked = true;
}; };
$promise->when($callback); $promise->onResolve($callback);
}); });
$this->assertLessThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000); $this->assertLessThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000);
@ -64,7 +64,7 @@ class PauseTest extends \PHPUnit\Framework\TestCase {
$invoked = true; $invoked = true;
}; };
$promise->when($callback); $promise->onResolve($callback);
}); });
$this->assertGreaterThanOrEqual($time, (microtime(true) - $start) * 1000); $this->assertGreaterThanOrEqual($time, (microtime(true) - $start) * 1000);

View File

@ -26,7 +26,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertTrue($invoked); $this->assertTrue($invoked);
$this->assertSame($value + 1, $result); $this->assertSame($value + 1, $result);
@ -50,7 +50,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertFalse($invoked); $this->assertFalse($invoked);
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);
@ -76,7 +76,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertTrue($invoked); $this->assertTrue($invoked);
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);
@ -103,7 +103,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertTrue($invoked); $this->assertTrue($invoked);
$this->assertSame($value + 1, $result); $this->assertSame($value + 1, $result);

View File

@ -29,7 +29,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->resolve($value); $this->placeholder->resolve($value);
@ -49,9 +49,9 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->resolve($value); $this->placeholder->resolve($value);
@ -73,7 +73,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$this->placeholder->resolve($value); $this->placeholder->resolve($value);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->assertSame(1, $invoked); $this->assertSame(1, $invoked);
$this->assertSame($value, $result); $this->assertSame($value, $result);
@ -93,9 +93,9 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$this->placeholder->resolve($value); $this->placeholder->resolve($value);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->assertSame(3, $invoked); $this->assertSame(3, $invoked);
$this->assertSame($value, $result); $this->assertSame($value, $result);
@ -118,7 +118,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
throw $expected; throw $expected;
}; };
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->resolve($expected); $this->placeholder->resolve($expected);
}); });
@ -145,7 +145,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$this->placeholder->resolve($expected); $this->placeholder->resolve($expected);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
}); });
$this->assertSame(1, $invoked); $this->assertSame(1, $invoked);
@ -160,7 +160,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$result = $exception; $result = $exception;
}; };
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->fail($exception); $this->placeholder->fail($exception);
@ -180,9 +180,9 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$result = $exception; $result = $exception;
}; };
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->fail($exception); $this->placeholder->fail($exception);
@ -204,7 +204,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$this->placeholder->fail($exception); $this->placeholder->fail($exception);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->assertSame(1, $invoked); $this->assertSame(1, $invoked);
$this->assertSame($exception, $result); $this->assertSame($exception, $result);
@ -224,9 +224,9 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$this->placeholder->fail($exception); $this->placeholder->fail($exception);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->assertSame(3, $invoked); $this->assertSame(3, $invoked);
$this->assertSame($exception, $result); $this->assertSame($exception, $result);
@ -249,7 +249,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
throw $expected; throw $expected;
}; };
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
$this->placeholder->fail(new \Exception); $this->placeholder->fail(new \Exception);
}); });
@ -276,7 +276,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$this->placeholder->fail(new \Exception); $this->placeholder->fail(new \Exception);
$this->placeholder->when($callback); $this->placeholder->onResolve($callback);
}); });
$this->assertSame(1, $invoked); $this->assertSame(1, $invoked);
@ -286,22 +286,22 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
$promise = $this->getMockBuilder(Promise::class)->getMock(); $promise = $this->getMockBuilder(Promise::class)->getMock();
$promise->expects($this->once()) $promise->expects($this->once())
->method("when") ->method("onResolve")
->with($this->callback("is_callable")); ->with($this->callback("is_callable"));
$this->placeholder->resolve($promise); $this->placeholder->resolve($promise);
$this->placeholder->when(function () {}); $this->placeholder->onResolve(function () {});
} }
public function testResolveWithPromiseAfterWhen() { public function testResolveWithPromiseAfterWhen() {
$promise = $this->getMockBuilder(Promise::class)->getMock(); $promise = $this->getMockBuilder(Promise::class)->getMock();
$promise->expects($this->once()) $promise->expects($this->once())
->method("when") ->method("onResolve")
->with($this->callback("is_callable")); ->with($this->callback("is_callable"));
$this->placeholder->when(function () {}); $this->placeholder->onResolve(function () {});
$this->placeholder->resolve($promise); $this->placeholder->resolve($promise);
} }
@ -321,7 +321,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
*/ */
public function testResolveAgainWithinWhenCallback() { public function testResolveAgainWithinWhenCallback() {
Loop::run(function () { Loop::run(function () {
$this->placeholder->when(function () { $this->placeholder->onResolve(function () {
$this->placeholder->resolve(); $this->placeholder->resolve();
}); });

View File

@ -39,7 +39,7 @@ class ProducerTest extends TestCase {
$producer->listen($callback); $producer->listen($callback);
$producer->when(function ($exception, $result) use ($value) { $producer->onResolve(function ($exception, $result) use ($value) {
$this->assertSame($result, $value); $this->assertSame($result, $value);
}); });
})); }));
@ -88,7 +88,7 @@ class ProducerTest extends TestCase {
$deferred->fail($exception); $deferred->fail($exception);
$producer->when(function ($reason) use ($exception) { $producer->onResolve(function ($reason) use ($exception) {
$this->assertSame($reason, $exception); $this->assertSame($reason, $exception);
}); });
}); });

View File

@ -78,7 +78,7 @@ class ProducerTraitTest extends TestCase {
$this->assertFalse($invoked); $this->assertFalse($invoked);
$this->producer->when(function ($exception) use (&$invoked, &$reason) { $this->producer->onResolve(function ($exception) use (&$invoked, &$reason) {
$invoked = true; $invoked = true;
$reason = $exception; $reason = $exception;
}); });
@ -178,7 +178,7 @@ class ProducerTraitTest extends TestCase {
$this->producer->resolve(); $this->producer->resolve();
$deferred->resolve(); $deferred->resolve();
$promise->when(function ($exception) use (&$invoked, &$reason) { $promise->onResolve(function ($exception) use (&$invoked, &$reason) {
$invoked = true; $invoked = true;
$reason = $exception; $reason = $exception;
}); });
@ -201,7 +201,7 @@ class ProducerTraitTest extends TestCase {
$this->producer->resolve(); $this->producer->resolve();
$deferred->fail(new \Exception); $deferred->fail(new \Exception);
$promise->when(function ($exception) use (&$invoked, &$reason) { $promise->onResolve(function ($exception) use (&$invoked, &$reason) {
$invoked = true; $invoked = true;
$reason = $exception; $reason = $exception;
}); });
@ -236,7 +236,7 @@ class ProducerTraitTest extends TestCase {
}); });
$promise = $this->producer->emit(1); $promise = $this->producer->emit(1);
$promise->when(function () use (&$invoked) { $promise->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
}); });
@ -254,7 +254,7 @@ class ProducerTraitTest extends TestCase {
}); });
$promise = $this->producer->emit(1); $promise = $this->producer->emit(1);
$promise->when(function () use (&$invoked) { $promise->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
}); });

View File

@ -64,7 +64,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
function testPromiseSucceed($value) function testPromiseSucceed($value)
{ {
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$promise->when(function($e, $v) use (&$invoked, $value) { $promise->onResolve(function($e, $v) use (&$invoked, $value) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame($value, $v); $this->assertSame($value, $v);
$invoked = true; $invoked = true;
@ -77,7 +77,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
function testWhenOnSucceededPromise($value) { function testWhenOnSucceededPromise($value) {
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$succeeder($value); $succeeder($value);
$promise->when(function($e, $v) use (&$invoked, $value) { $promise->onResolve(function($e, $v) use (&$invoked, $value) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame($value, $v); $this->assertSame($value, $v);
$invoked = true; $invoked = true;
@ -89,12 +89,12 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$invoked = 0; $invoked = 0;
$promise->when(function($e, $v) use (&$invoked) { $promise->onResolve(function($e, $v) use (&$invoked) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame(true, $v); $this->assertSame(true, $v);
$invoked++; $invoked++;
}); });
$promise->when(function($e, $v) use (&$invoked) { $promise->onResolve(function($e, $v) use (&$invoked) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame(true, $v); $this->assertSame(true, $v);
$invoked++; $invoked++;
@ -102,12 +102,12 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
$succeeder(true); $succeeder(true);
$promise->when(function($e, $v) use (&$invoked) { $promise->onResolve(function($e, $v) use (&$invoked) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame(true, $v); $this->assertSame(true, $v);
$invoked++; $invoked++;
}); });
$promise->when(function($e, $v) use (&$invoked) { $promise->onResolve(function($e, $v) use (&$invoked) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame(true, $v); $this->assertSame(true, $v);
$invoked++; $invoked++;
@ -118,7 +118,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
function testPromiseExceptionFailure() { function testPromiseExceptionFailure() {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$promise->when(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(get_class($e), "RuntimeException");
$invoked = true; $invoked = true;
}); });
@ -129,7 +129,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
function testWhenOnExceptionFailedPromise() { function testWhenOnExceptionFailedPromise() {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$failer(new \RuntimeException); $failer(new \RuntimeException);
$promise->when(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(get_class($e), "RuntimeException");
$invoked = true; $invoked = true;
}); });
@ -140,22 +140,22 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$invoked = 0; $invoked = 0;
$promise->when(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(get_class($e), "RuntimeException");
$invoked++; $invoked++;
}); });
$promise->when(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(get_class($e), "RuntimeException");
$invoked++; $invoked++;
}); });
$failer(new \RuntimeException); $failer(new \RuntimeException);
$promise->when(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(get_class($e), "RuntimeException");
$invoked++; $invoked++;
}); });
$promise->when(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "RuntimeException"); $this->assertSame(get_class($e), "RuntimeException");
$invoked++; $invoked++;
}); });
@ -169,7 +169,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
} }
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$promise->when(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "Error"); $this->assertSame(get_class($e), "Error");
$invoked = true; $invoked = true;
}); });
@ -184,7 +184,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$failer(new \Error); $failer(new \Error);
$promise->when(function ($e) use (&$invoked) { $promise->onResolve(function ($e) use (&$invoked) {
$this->assertSame(get_class($e), "Error"); $this->assertSame(get_class($e), "Error");
$invoked = true; $invoked = true;
}); });
@ -207,7 +207,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
$ex = true; $ex = true;
} }
if (!$ex) { if (!$ex) {
$promise->when(function ($e, $v) use (&$invoked) { $promise->onResolve(function ($e, $v) use (&$invoked) {
$invoked = true; $invoked = true;
$this->assertFalse($v instanceof Promise); $this->assertFalse($v instanceof Promise);
}); });
@ -225,7 +225,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$succeeder(true); $succeeder(true);
$promise->when(function ($e, $v) use (&$invoked, $promise) { $promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame(true, $v); $this->assertSame(true, $v);
$invoked++; $invoked++;
@ -234,7 +234,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
}); });
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$promise->when(function ($e, $v) use (&$invoked, $promise) { $promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame(true, $v); $this->assertSame(true, $v);
$invoked++; $invoked++;
@ -256,14 +256,14 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
}); });
list($promise, $succeeder) = $this->promise(); list($promise, $succeeder) = $this->promise();
$promise->when(function ($e, $v) use (&$invoked, $promise) { $promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame(true, $v); $this->assertSame(true, $v);
$invoked++; $invoked++;
throw new \Exception; throw new \Exception;
}); });
$promise->when(function ($e, $v) use (&$invoked, $promise) { $promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
$this->assertSame(null, $e); $this->assertSame(null, $e);
$this->assertSame(true, $v); $this->assertSame(true, $v);
$invoked++; $invoked++;
@ -284,7 +284,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$exception = new \Exception; $exception = new \Exception;
$failer($exception); $failer($exception);
$promise->when(function ($e, $v) use (&$invoked, $exception) { $promise->onResolve(function ($e, $v) use (&$invoked, $exception) {
$this->assertSame($exception, $e); $this->assertSame($exception, $e);
$this->assertNull($v); $this->assertNull($v);
$invoked++; $invoked++;
@ -294,7 +294,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
list($promise, , $failer) = $this->promise(); list($promise, , $failer) = $this->promise();
$exception = new \Exception; $exception = new \Exception;
$promise->when(function ($e, $v) use (&$invoked, $exception) { $promise->onResolve(function ($e, $v) use (&$invoked, $exception) {
$this->assertSame($exception, $e); $this->assertSame($exception, $e);
$this->assertNull($v); $this->assertNull($v);
$invoked++; $invoked++;
@ -316,12 +316,12 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
$expectedData = "15.24"; $expectedData = "15.24";
$promise->when(function($e, int $v) use (&$invoked, $expectedData) { $promise->onResolve(function($e, int $v) use (&$invoked, $expectedData) {
$invoked++; $invoked++;
$this->assertSame((int) $expectedData, $v); $this->assertSame((int) $expectedData, $v);
}); });
$succeeder($expectedData); $succeeder($expectedData);
$promise->when(function($e, int $v) use (&$invoked, $expectedData) { $promise->onResolve(function($e, int $v) use (&$invoked, $expectedData) {
$invoked++; $invoked++;
$this->assertSame((int) $expectedData, $v); $this->assertSame((int) $expectedData, $v);
}); });
@ -334,9 +334,9 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
$invoked = false; $invoked = false;
$promise = new Promise; $promise = new Promise;
$promise->when(function () { }); $promise->onResolve(function () { });
$promise->when(function () { }); $promise->onResolve(function () { });
$promise->when(function () use (&$invoked) { $promise->onResolve(function () use (&$invoked) {
$invoked = true; $invoked = true;
$this->assertLessThan(30, count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))); $this->assertLessThan(30, count(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)));
}); });
@ -345,8 +345,8 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
$f = function () use (&$f, &$count, &$last) { $f = function () use (&$f, &$count, &$last) {
$p = new Promise; $p = new Promise;
$p->when(function () { }); $p->onResolve(function () { });
$p->when(function () { }); $p->onResolve(function () { });
$last->resolve($p); $last->resolve($p);
$last = $p; $last = $p;

View File

@ -21,7 +21,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\some($promises)->when($callback); Promise\some($promises)->onResolve($callback);
$this->assertSame([[], [1, 2, 3]], $result); $this->assertSame([[], [1, 2, 3]], $result);
} }
@ -34,7 +34,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
Promise\some($promises)->when($callback); Promise\some($promises)->onResolve($callback);
$this->assertInstanceOf(MultiReasonException::class, $reason); $this->assertInstanceOf(MultiReasonException::class, $reason);
$this->assertEquals([$exception, $exception, $exception], $reason->getReasons()); $this->assertEquals([$exception, $exception, $exception], $reason->getReasons());
@ -48,7 +48,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\some($promises)->when($callback); Promise\some($promises)->onResolve($callback);
$this->assertSame([[0 => $exception, 1 => $exception], [2 => 3]], $result); $this->assertSame([[0 => $exception, 1 => $exception], [2 => 3]], $result);
} }
@ -65,7 +65,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\some($promises)->when($callback); Promise\some($promises)->onResolve($callback);
}); });
$this->assertEquals([[], [0 => 1, 1 => 2, 2 => 3]], $result); $this->assertEquals([[], [0 => 1, 1 => 2, 2 => 3]], $result);
@ -85,7 +85,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
Promise\some($promises)->when($callback); Promise\some($promises)->onResolve($callback);
}); });
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);

View File

@ -31,7 +31,7 @@ class StreamFromIterableTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);
@ -51,7 +51,7 @@ class StreamFromIterableTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertSame(\range(1, 2), $results); $this->assertSame(\range(1, 2), $results);

View File

@ -50,7 +50,7 @@ class StreamMapTest extends \PHPUnit\Framework\TestCase {
$results[] = $value; $results[] = $value;
}); });
$stream->when(function ($exception, $value) use (&$result) { $stream->onResolve(function ($exception, $value) use (&$result) {
$result = $value; $result = $value;
}); });
}); });
@ -85,7 +85,7 @@ class StreamMapTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);
@ -121,7 +121,7 @@ class StreamMapTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertSame(\count($values), $count); $this->assertSame(\count($values), $count);
@ -145,7 +145,7 @@ class StreamMapTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$stream->when($callback); $stream->onResolve($callback);
}); });
$this->assertFalse($invoked); $this->assertFalse($invoked);

View File

@ -25,7 +25,7 @@ class SuccessTest extends \PHPUnit\Framework\TestCase {
$success = new Success($value); $success = new Success($value);
$success->when($callback); $success->onResolve($callback);
$this->assertSame(1, $invoked); $this->assertSame(1, $invoked);
$this->assertSame($value, $result); $this->assertSame($value, $result);
@ -50,7 +50,7 @@ class SuccessTest extends \PHPUnit\Framework\TestCase {
$success = new Success; $success = new Success;
$success->when($callback); $success->onResolve($callback);
}); });
$this->assertSame(1, $invoked); $this->assertSame(1, $invoked);

View File

@ -23,7 +23,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertSame($value, $result); $this->assertSame($value, $result);
}); });
@ -42,7 +42,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertSame($exception, $reason); $this->assertSame($exception, $reason);
}); });
@ -64,7 +64,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
}); });
$this->assertSame($value, $result); $this->assertSame($value, $result);
@ -84,7 +84,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
$reason = $exception; $reason = $exception;
}; };
$promise->when($callback); $promise->onResolve($callback);
}); });
$this->assertInstanceOf(\Amp\TimeoutException::class, $reason); $this->assertInstanceOf(\Amp\TimeoutException::class, $reason);
@ -106,7 +106,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
$result = $value; $result = $value;
}; };
$promise->when($callback); $promise->onResolve($callback);
$this->assertSame($value, $result); $this->assertSame($value, $result);
}); });