mirror of
https://github.com/danog/amp.git
synced 2024-11-30 04:29:08 +01:00
Rename Promise::when to Promise::onResolve, resolves #77
This commit is contained in:
parent
3b6ca19dfe
commit
ce269fa516
@ -14,7 +14,7 @@ The basic unit of concurrency in Amp applications is the `Amp\Promise`. These ob
|
||||
|
||||
```php
|
||||
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 |
|
||||
| --------- | ----------------------------------------------------------|
|
||||
| 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
|
||||
|
||||
$promise = someFunctionThatReturnsAPromise();
|
||||
$promise->when(function (Throwable $error = null, $result = null) {
|
||||
$promise->onResolve(function (Throwable $error = null, $result = null) {
|
||||
if ($error) {
|
||||
printf(
|
||||
"Something went wrong:\n%s\n",
|
||||
@ -66,11 +66,11 @@ Returns the corresponding `Promise` instance. `Deferred` and `Promise` are separ
|
||||
|
||||
#### `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()`
|
||||
|
||||
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.
|
||||
|
||||
|
@ -19,7 +19,7 @@ Loop::run(function () {
|
||||
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) {
|
||||
printf("Stream failed: %s\n", $exception->getMessage());
|
||||
return;
|
||||
|
@ -25,7 +25,7 @@ final class Coroutine implements Promise {
|
||||
private $generator;
|
||||
|
||||
/** @var callable(\Throwable|null $exception, mixed $value): void */
|
||||
private $when;
|
||||
private $onResolve;
|
||||
|
||||
/** @var int */
|
||||
private $depth = 0;
|
||||
@ -40,10 +40,10 @@ final class Coroutine implements Promise {
|
||||
* @param \Throwable|null $exception Exception to be thrown 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.
|
||||
Loop::defer(function () use ($exception, $value) {
|
||||
($this->when)($exception, $value);
|
||||
($this->onResolve)($exception, $value);
|
||||
});
|
||||
return;
|
||||
}
|
||||
@ -67,7 +67,7 @@ final class Coroutine implements Promise {
|
||||
}
|
||||
|
||||
++$this->depth;
|
||||
$yielded->when($this->when);
|
||||
$yielded->onResolve($this->onResolve);
|
||||
--$this->depth;
|
||||
} catch (\Throwable $exception) {
|
||||
$this->dispose($exception);
|
||||
@ -87,7 +87,7 @@ final class Coroutine implements Promise {
|
||||
}
|
||||
|
||||
++$this->depth;
|
||||
$yielded->when($this->when);
|
||||
$yielded->onResolve($this->onResolve);
|
||||
--$this->depth;
|
||||
} catch (\Throwable $exception) {
|
||||
$this->dispose($exception);
|
||||
|
@ -19,7 +19,7 @@ final class Failure implements Stream {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function when(callable $onResolved) {
|
||||
public function onResolve(callable $onResolved) {
|
||||
try {
|
||||
$onResolved($this->exception, null);
|
||||
} catch (\Throwable $exception) {
|
||||
|
@ -21,16 +21,16 @@ trait Placeholder {
|
||||
/** @var mixed */
|
||||
private $result;
|
||||
|
||||
/** @var callable|\Amp\Internal\WhenQueue|null */
|
||||
/** @var callable|\Amp\Internal\ResolutionQueue|null */
|
||||
private $onResolved;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function when(callable $onResolved) {
|
||||
public function onResolve(callable $onResolved) {
|
||||
if ($this->resolved) {
|
||||
if ($this->result instanceof Promise) {
|
||||
$this->result->when($onResolved);
|
||||
$this->result->onResolve($onResolved);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -49,8 +49,8 @@ trait Placeholder {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->onResolved instanceof WhenQueue) {
|
||||
$this->onResolved = new WhenQueue($this->onResolved);
|
||||
if (!$this->onResolved instanceof ResolutionQueue) {
|
||||
$this->onResolved = new ResolutionQueue($this->onResolved);
|
||||
}
|
||||
|
||||
$this->onResolved->push($onResolved);
|
||||
@ -81,7 +81,7 @@ trait Placeholder {
|
||||
$this->onResolved = null;
|
||||
|
||||
if ($this->result instanceof Promise) {
|
||||
$this->result->when($onResolved);
|
||||
$this->result->onResolve($onResolved);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ trait Producer {
|
||||
|
||||
if ($value instanceof Promise) {
|
||||
$deferred = new Deferred;
|
||||
$value->when(function ($e, $v) use ($deferred) {
|
||||
$value->onResolve(function ($e, $v) use ($deferred) {
|
||||
if ($this->resolved) {
|
||||
$deferred->fail(
|
||||
new \Error("The stream was resolved before the promise result could be emitted")
|
||||
@ -113,7 +113,7 @@ trait Producer {
|
||||
};
|
||||
|
||||
foreach ($promises as $promise) {
|
||||
$promise->when($f);
|
||||
$promise->onResolve($f);
|
||||
}
|
||||
|
||||
return $deferred->promise();
|
||||
|
@ -9,7 +9,7 @@ use Amp\Loop;
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class WhenQueue {
|
||||
class ResolutionQueue {
|
||||
/** @var callable[] */
|
||||
private $queue = [];
|
||||
|
@ -5,9 +5,9 @@ namespace Amp;
|
||||
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
|
||||
* the promise). $promisor can return a promise or any value. If $promisor throws an exception, the promise fails with
|
||||
* that exception.
|
||||
* Creates a promise that calls $promisor only when the result of the promise is requested (i.e. onResolve() is called
|
||||
* on the promise). $promisor can return a promise or any value. If $promisor throws an exception, the promise fails
|
||||
* with that exception.
|
||||
*/
|
||||
class LazyPromise implements Promise {
|
||||
/** @var callable|null */
|
||||
@ -26,7 +26,7 @@ class LazyPromise implements Promise {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function when(callable $onResolved) {
|
||||
public function onResolve(callable $onResolved) {
|
||||
if ($this->promise === null) {
|
||||
$provider = $this->promisor;
|
||||
$this->promisor = null;
|
||||
@ -46,6 +46,6 @@ class LazyPromise implements Promise {
|
||||
}
|
||||
}
|
||||
|
||||
$this->promise->when($onResolved);
|
||||
$this->promise->onResolve($onResolved);
|
||||
}
|
||||
}
|
@ -68,7 +68,7 @@ class Listener implements Iterator {
|
||||
$result = &$this->result;
|
||||
$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;
|
||||
|
||||
if ($exception) {
|
||||
|
@ -43,7 +43,7 @@ class Message implements Iterator, Promise {
|
||||
public function __construct(Stream $stream) {
|
||||
$this->listener = new Listener($stream);
|
||||
|
||||
$stream->when(function ($exception, $value) {
|
||||
$stream->onResolve(function ($exception, $value) {
|
||||
if ($exception) {
|
||||
$this->fail($exception);
|
||||
return;
|
||||
|
@ -19,7 +19,7 @@ final class Producer implements Stream {
|
||||
|
||||
Loop::defer(function () use ($result) {
|
||||
$coroutine = new Coroutine($result);
|
||||
$coroutine->when(function ($exception, $value) {
|
||||
$coroutine->onResolve(function ($exception, $value) {
|
||||
if ($this->resolved) {
|
||||
return;
|
||||
}
|
||||
|
@ -16,5 +16,5 @@ interface Promise {
|
||||
*
|
||||
* @return mixed Return type and value are unspecified.
|
||||
*/
|
||||
public function when(callable $onResolved);
|
||||
public function onResolve(callable $onResolved);
|
||||
}
|
@ -28,7 +28,7 @@ final class Success implements Stream {
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function when(callable $onResolved) {
|
||||
public function onResolve(callable $onResolved) {
|
||||
try {
|
||||
$onResolved(null, $this->value);
|
||||
} catch (\Throwable $exception) {
|
||||
|
@ -158,7 +158,7 @@ namespace Amp\Promise {
|
||||
}
|
||||
}
|
||||
|
||||
$promise->when(function ($exception) {
|
||||
$promise->onResolve(function ($exception) {
|
||||
if ($exception) {
|
||||
throw $exception;
|
||||
}
|
||||
@ -186,7 +186,7 @@ namespace Amp\Promise {
|
||||
|
||||
$resolved = false;
|
||||
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();
|
||||
$resolved = true;
|
||||
$exception = $e;
|
||||
@ -226,7 +226,7 @@ namespace Amp\Promise {
|
||||
|
||||
$deferred = new Deferred;
|
||||
|
||||
$promise->when(function ($exception, $value) use ($deferred, $functor) {
|
||||
$promise->onResolve(function ($exception, $value) use ($deferred, $functor) {
|
||||
if ($exception) {
|
||||
$deferred->fail($exception);
|
||||
return;
|
||||
@ -263,7 +263,7 @@ namespace Amp\Promise {
|
||||
|
||||
$deferred = new Deferred;
|
||||
|
||||
$promise->when(function ($exception, $value) use ($deferred, $className, $functor) {
|
||||
$promise->onResolve(function ($exception, $value) use ($deferred, $className, $functor) {
|
||||
if (!$exception) {
|
||||
$deferred->resolve($value);
|
||||
return;
|
||||
@ -317,7 +317,7 @@ namespace Amp\Promise {
|
||||
});
|
||||
Loop::unreference($watcher);
|
||||
|
||||
$promise->when(function () use (&$resolved, $promise, $deferred, $watcher) {
|
||||
$promise->onResolve(function () use (&$resolved, $promise, $deferred, $watcher) {
|
||||
Loop::cancel($watcher);
|
||||
|
||||
if ($resolved) {
|
||||
@ -388,7 +388,7 @@ namespace Amp\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) {
|
||||
$errors[$key] = $error;
|
||||
} else {
|
||||
@ -432,7 +432,7 @@ namespace Amp\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) {
|
||||
return;
|
||||
}
|
||||
@ -480,7 +480,7 @@ namespace Amp\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) {
|
||||
return;
|
||||
}
|
||||
@ -528,7 +528,7 @@ namespace Amp\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) {
|
||||
$exceptions[$key] = $exception;
|
||||
} 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;
|
||||
|
||||
if ($exception) {
|
||||
@ -730,7 +730,7 @@ namespace Amp\Stream {
|
||||
$promise = Promise\all($previous);
|
||||
}
|
||||
|
||||
$promise->when(function ($exception, array $values = null) use ($emitter) {
|
||||
$promise->onResolve(function ($exception, array $values = null) use ($emitter) {
|
||||
if ($exception) {
|
||||
$emitter->fail($exception);
|
||||
return;
|
||||
|
@ -15,7 +15,7 @@ class PromiseMock {
|
||||
}
|
||||
|
||||
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 ($onRejected) {
|
||||
$onRejected($exception);
|
||||
@ -62,7 +62,7 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = Promise\adapt($promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$result) {
|
||||
$result = $value;
|
||||
});
|
||||
|
||||
@ -79,7 +79,7 @@ class AdaptTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$promise = Promise\adapt($promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
|
@ -13,7 +13,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\all([])->when($callback);
|
||||
Promise\all([])->onResolve($callback);
|
||||
|
||||
$this->assertSame([], $result);
|
||||
}
|
||||
@ -25,7 +25,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\all($promises)->when($callback);
|
||||
Promise\all($promises)->onResolve($callback);
|
||||
|
||||
$this->assertSame([1, 2, 3], $result);
|
||||
}
|
||||
@ -42,7 +42,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\all($promises)->when($callback);
|
||||
Promise\all($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([1, 2, 3], $result);
|
||||
@ -62,7 +62,7 @@ class AllTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\all($promises)->when($callback);
|
||||
Promise\all($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -14,7 +14,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\any([])->when($callback);
|
||||
Promise\any([])->onResolve($callback);
|
||||
|
||||
$this->assertSame([[], []], $result);
|
||||
}
|
||||
@ -26,7 +26,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\any($promises)->when($callback);
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
|
||||
$this->assertEquals([[], [1, 2, 3]], $result);
|
||||
}
|
||||
@ -39,7 +39,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\any($promises)->when($callback);
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
|
||||
$this->assertEquals([[$exception, $exception, $exception], []], $result);
|
||||
}
|
||||
@ -52,7 +52,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\any($promises)->when($callback);
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
|
||||
$this->assertEquals([[1 => $exception], [0 => 1, 2 => 3]], $result);
|
||||
}
|
||||
@ -69,7 +69,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\any($promises)->when($callback);
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([[], [1, 2, 3]], $result);
|
||||
@ -93,7 +93,7 @@ class AnyTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\any($promises)->when($callback);
|
||||
Promise\any($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -18,7 +18,7 @@ class CallTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -35,7 +35,7 @@ class CallTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -52,7 +52,7 @@ class CallTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -69,7 +69,7 @@ class CallTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -86,7 +86,7 @@ class CallTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Coroutine::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertFalse($invoked);
|
||||
$this->assertSame($value, $result);
|
||||
@ -51,7 +51,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertTrue($invoked);
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -78,7 +78,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertTrue($invoked);
|
||||
$this->assertNotSame($exception, $reason);
|
||||
@ -105,7 +105,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertFalse($invoked);
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -133,7 +133,7 @@ class CaptureTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertTrue($invoked);
|
||||
$this->assertSame($exception, $reason);
|
||||
|
@ -58,7 +58,7 @@ class ConcatTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame(\range(1, 6), $results);
|
||||
|
@ -39,7 +39,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$this->assertNull($yielded);
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -159,7 +159,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -177,7 +177,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -198,7 +198,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -219,7 +219,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -241,7 +241,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -265,7 +265,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -284,7 +284,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -309,7 +309,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -335,7 +335,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -363,7 +363,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
});
|
||||
@ -394,7 +394,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
});
|
||||
@ -422,7 +422,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception) use (&$reason) {
|
||||
$coroutine->onResolve(function ($exception) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -446,7 +446,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function () use (&$invoked) {
|
||||
$coroutine->onResolve(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
});
|
||||
@ -475,7 +475,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function () use (&$invoked) {
|
||||
$coroutine->onResolve(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
});
|
||||
@ -495,7 +495,7 @@ class CoroutineTest extends TestCase {
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$invoked = false;
|
||||
$coroutine->when(function () use (&$invoked) {
|
||||
$coroutine->onResolve(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
||||
@ -525,7 +525,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -548,7 +548,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -571,7 +571,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -593,7 +593,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -612,7 +612,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$this->assertInstanceOf(Promise::class, $promise);
|
||||
|
||||
$promise->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -631,7 +631,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -656,7 +656,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -684,7 +684,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -705,7 +705,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -727,7 +727,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -748,7 +748,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -770,7 +770,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -792,7 +792,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
@ -814,7 +814,7 @@ class CoroutineTest extends TestCase {
|
||||
|
||||
$coroutine = new Coroutine($generator());
|
||||
|
||||
$coroutine->when(function ($exception, $value) use (&$reason, &$result) {
|
||||
$coroutine->onResolve(function ($exception, $value) use (&$reason, &$result) {
|
||||
$reason = $exception;
|
||||
$result = $value;
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ class DeferredTest extends \PHPUnit\Framework\TestCase {
|
||||
$promise = $this->deferred->promise();
|
||||
|
||||
$invoked = false;
|
||||
$promise->when(function ($exception, $value) use (&$invoked, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$invoked, &$result) {
|
||||
$invoked = true;
|
||||
$result = $value;
|
||||
});
|
||||
@ -45,7 +45,7 @@ class DeferredTest extends \PHPUnit\Framework\TestCase {
|
||||
$promise = $this->deferred->promise();
|
||||
|
||||
$invoked = false;
|
||||
$promise->when(function ($exception, $value) use (&$invoked, &$result) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$invoked, &$result) {
|
||||
$invoked = true;
|
||||
$result = $exception;
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ class FailureTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$success = new Failure($exception);
|
||||
|
||||
$success->when($callback);
|
||||
$success->onResolve($callback);
|
||||
|
||||
$this->assertSame(1, $invoked);
|
||||
$this->assertSame($exception, $reason);
|
||||
|
@ -46,7 +46,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
$results[] = $value;
|
||||
});
|
||||
|
||||
$stream->when(function ($exception, $value) use (&$result) {
|
||||
$stream->onResolve(function ($exception, $value) use (&$result) {
|
||||
$result = $value;
|
||||
});
|
||||
});
|
||||
@ -80,7 +80,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -102,7 +102,7 @@ class FilterTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertFalse($invoked);
|
||||
|
@ -26,7 +26,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\first($promises)->when($callback);
|
||||
Promise\first($promises)->onResolve($callback);
|
||||
|
||||
$this->assertSame(1, $result);
|
||||
}
|
||||
@ -39,7 +39,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
Promise\first($promises)->when($callback);
|
||||
Promise\first($promises)->onResolve($callback);
|
||||
|
||||
$this->assertInstanceOf(MultiReasonException::class, $reason);
|
||||
$this->assertEquals([$exception, $exception, $exception], $reason->getReasons());
|
||||
@ -53,7 +53,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\first($promises)->when($callback);
|
||||
Promise\first($promises)->onResolve($callback);
|
||||
|
||||
$this->assertSame(3, $result);
|
||||
}
|
||||
@ -70,7 +70,7 @@ class FirstTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\first($promises)->when($callback);
|
||||
Promise\first($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame(3, $result);
|
||||
|
@ -27,7 +27,7 @@ class LazyPromiseTest extends TestCase {
|
||||
return $value;
|
||||
});
|
||||
|
||||
$lazy->when(function ($exception, $value) use (&$result) {
|
||||
$lazy->onResolve(function ($exception, $value) use (&$result) {
|
||||
$result = $value;
|
||||
});
|
||||
|
||||
@ -44,7 +44,7 @@ class LazyPromiseTest extends TestCase {
|
||||
return $promise;
|
||||
});
|
||||
|
||||
$lazy->when(function ($exception, $value) use (&$result) {
|
||||
$lazy->onResolve(function ($exception, $value) use (&$result) {
|
||||
$result = $value;
|
||||
});
|
||||
|
||||
@ -61,7 +61,7 @@ class LazyPromiseTest extends TestCase {
|
||||
return $promise;
|
||||
});
|
||||
|
||||
$lazy->when(function ($exception, $value) use (&$reason) {
|
||||
$lazy->onResolve(function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -77,7 +77,7 @@ class LazyPromiseTest extends TestCase {
|
||||
throw $exception;
|
||||
});
|
||||
|
||||
$lazy->when(function ($exception, $value) use (&$reason) {
|
||||
$lazy->onResolve(function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
@ -94,7 +94,7 @@ class LazyPromiseTest extends TestCase {
|
||||
return $promise;
|
||||
});
|
||||
|
||||
$lazy->when(function ($exception, $value) use (&$result) {
|
||||
$lazy->onResolve(function ($exception, $value) use (&$result) {
|
||||
$result = $value;
|
||||
});
|
||||
|
||||
@ -111,7 +111,7 @@ class LazyPromiseTest extends TestCase {
|
||||
return $promise;
|
||||
});
|
||||
|
||||
$lazy->when(function ($exception, $value) use (&$reason) {
|
||||
$lazy->onResolve(function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
|
@ -213,7 +213,7 @@ class ListenerTest extends \PHPUnit\Framework\TestCase {
|
||||
unset($listener);
|
||||
|
||||
$invoked = false;
|
||||
$promise->when(function () use (&$invoked) {
|
||||
$promise->onResolve(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
||||
@ -231,7 +231,7 @@ class ListenerTest extends \PHPUnit\Framework\TestCase {
|
||||
$promise = $emitter->emit(2);
|
||||
|
||||
$invoked = false;
|
||||
$promise->when(function () use (&$invoked) {
|
||||
$promise->onResolve(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
||||
@ -244,7 +244,7 @@ class ListenerTest extends \PHPUnit\Framework\TestCase {
|
||||
$listener = new Listener($emitter->stream());
|
||||
|
||||
$promise = $listener->advance();
|
||||
$promise->when(function ($exception, $value) use (&$reason) {
|
||||
$promise->onResolve(function ($exception, $value) use (&$reason) {
|
||||
$reason = $exception;
|
||||
});
|
||||
|
||||
|
@ -53,7 +53,7 @@ class MergeTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame($exception, $reason);
|
||||
|
@ -18,7 +18,7 @@ class PauseTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertGreaterThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000);
|
||||
@ -39,7 +39,7 @@ class PauseTest extends \PHPUnit\Framework\TestCase {
|
||||
$invoked = true;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertLessThanOrEqual($time - 1 /* 1ms grace period */, (microtime(true) - $start) * 1000);
|
||||
@ -64,7 +64,7 @@ class PauseTest extends \PHPUnit\Framework\TestCase {
|
||||
$invoked = true;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertGreaterThanOrEqual($time, (microtime(true) - $start) * 1000);
|
||||
|
@ -26,7 +26,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertTrue($invoked);
|
||||
$this->assertSame($value + 1, $result);
|
||||
@ -50,7 +50,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertFalse($invoked);
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -76,7 +76,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertTrue($invoked);
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -103,7 +103,7 @@ class PipeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertTrue($invoked);
|
||||
$this->assertSame($value + 1, $result);
|
||||
|
@ -29,7 +29,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->placeholder->resolve($value);
|
||||
|
||||
@ -49,9 +49,9 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->placeholder->resolve($value);
|
||||
|
||||
@ -73,7 +73,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$this->placeholder->resolve($value);
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->assertSame(1, $invoked);
|
||||
$this->assertSame($value, $result);
|
||||
@ -93,9 +93,9 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$this->placeholder->resolve($value);
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->assertSame(3, $invoked);
|
||||
$this->assertSame($value, $result);
|
||||
@ -118,7 +118,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
throw $expected;
|
||||
};
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->placeholder->resolve($expected);
|
||||
});
|
||||
@ -145,7 +145,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$this->placeholder->resolve($expected);
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame(1, $invoked);
|
||||
@ -160,7 +160,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $exception;
|
||||
};
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->placeholder->fail($exception);
|
||||
|
||||
@ -180,9 +180,9 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $exception;
|
||||
};
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->placeholder->fail($exception);
|
||||
|
||||
@ -204,7 +204,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$this->placeholder->fail($exception);
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->assertSame(1, $invoked);
|
||||
$this->assertSame($exception, $result);
|
||||
@ -224,9 +224,9 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$this->placeholder->fail($exception);
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->assertSame(3, $invoked);
|
||||
$this->assertSame($exception, $result);
|
||||
@ -249,7 +249,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
throw $expected;
|
||||
};
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
|
||||
$this->placeholder->fail(new \Exception);
|
||||
});
|
||||
@ -276,7 +276,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$this->placeholder->fail(new \Exception);
|
||||
|
||||
$this->placeholder->when($callback);
|
||||
$this->placeholder->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame(1, $invoked);
|
||||
@ -286,22 +286,22 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
$promise = $this->getMockBuilder(Promise::class)->getMock();
|
||||
|
||||
$promise->expects($this->once())
|
||||
->method("when")
|
||||
->method("onResolve")
|
||||
->with($this->callback("is_callable"));
|
||||
|
||||
$this->placeholder->resolve($promise);
|
||||
|
||||
$this->placeholder->when(function () {});
|
||||
$this->placeholder->onResolve(function () {});
|
||||
}
|
||||
|
||||
public function testResolveWithPromiseAfterWhen() {
|
||||
$promise = $this->getMockBuilder(Promise::class)->getMock();
|
||||
|
||||
$promise->expects($this->once())
|
||||
->method("when")
|
||||
->method("onResolve")
|
||||
->with($this->callback("is_callable"));
|
||||
|
||||
$this->placeholder->when(function () {});
|
||||
$this->placeholder->onResolve(function () {});
|
||||
|
||||
$this->placeholder->resolve($promise);
|
||||
}
|
||||
@ -321,7 +321,7 @@ class PlaceholderTraitTest extends \PHPUnit\Framework\TestCase {
|
||||
*/
|
||||
public function testResolveAgainWithinWhenCallback() {
|
||||
Loop::run(function () {
|
||||
$this->placeholder->when(function () {
|
||||
$this->placeholder->onResolve(function () {
|
||||
$this->placeholder->resolve();
|
||||
});
|
||||
|
||||
|
@ -39,7 +39,7 @@ class ProducerTest extends TestCase {
|
||||
|
||||
$producer->listen($callback);
|
||||
|
||||
$producer->when(function ($exception, $result) use ($value) {
|
||||
$producer->onResolve(function ($exception, $result) use ($value) {
|
||||
$this->assertSame($result, $value);
|
||||
});
|
||||
}));
|
||||
@ -88,7 +88,7 @@ class ProducerTest extends TestCase {
|
||||
|
||||
$deferred->fail($exception);
|
||||
|
||||
$producer->when(function ($reason) use ($exception) {
|
||||
$producer->onResolve(function ($reason) use ($exception) {
|
||||
$this->assertSame($reason, $exception);
|
||||
});
|
||||
});
|
||||
|
@ -78,7 +78,7 @@ class ProducerTraitTest extends TestCase {
|
||||
|
||||
$this->assertFalse($invoked);
|
||||
|
||||
$this->producer->when(function ($exception) use (&$invoked, &$reason) {
|
||||
$this->producer->onResolve(function ($exception) use (&$invoked, &$reason) {
|
||||
$invoked = true;
|
||||
$reason = $exception;
|
||||
});
|
||||
@ -178,7 +178,7 @@ class ProducerTraitTest extends TestCase {
|
||||
$this->producer->resolve();
|
||||
$deferred->resolve();
|
||||
|
||||
$promise->when(function ($exception) use (&$invoked, &$reason) {
|
||||
$promise->onResolve(function ($exception) use (&$invoked, &$reason) {
|
||||
$invoked = true;
|
||||
$reason = $exception;
|
||||
});
|
||||
@ -201,7 +201,7 @@ class ProducerTraitTest extends TestCase {
|
||||
$this->producer->resolve();
|
||||
$deferred->fail(new \Exception);
|
||||
|
||||
$promise->when(function ($exception) use (&$invoked, &$reason) {
|
||||
$promise->onResolve(function ($exception) use (&$invoked, &$reason) {
|
||||
$invoked = true;
|
||||
$reason = $exception;
|
||||
});
|
||||
@ -236,7 +236,7 @@ class ProducerTraitTest extends TestCase {
|
||||
});
|
||||
|
||||
$promise = $this->producer->emit(1);
|
||||
$promise->when(function () use (&$invoked) {
|
||||
$promise->onResolve(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
||||
@ -254,7 +254,7 @@ class ProducerTraitTest extends TestCase {
|
||||
});
|
||||
|
||||
$promise = $this->producer->emit(1);
|
||||
$promise->when(function () use (&$invoked) {
|
||||
$promise->onResolve(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
});
|
||||
|
||||
|
@ -64,7 +64,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
function testPromiseSucceed($value)
|
||||
{
|
||||
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($value, $v);
|
||||
$invoked = true;
|
||||
@ -77,7 +77,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
function testWhenOnSucceededPromise($value) {
|
||||
list($promise, $succeeder) = $this->promise();
|
||||
$succeeder($value);
|
||||
$promise->when(function($e, $v) use (&$invoked, $value) {
|
||||
$promise->onResolve(function($e, $v) use (&$invoked, $value) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame($value, $v);
|
||||
$invoked = true;
|
||||
@ -89,12 +89,12 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
list($promise, $succeeder) = $this->promise();
|
||||
$invoked = 0;
|
||||
|
||||
$promise->when(function($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function($e, $v) use (&$invoked) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
});
|
||||
$promise->when(function($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function($e, $v) use (&$invoked) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
@ -102,12 +102,12 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$succeeder(true);
|
||||
|
||||
$promise->when(function($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function($e, $v) use (&$invoked) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
});
|
||||
$promise->when(function($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function($e, $v) use (&$invoked) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
@ -118,7 +118,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
function testPromiseExceptionFailure() {
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$promise->when(function ($e) use (&$invoked) {
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "RuntimeException");
|
||||
$invoked = true;
|
||||
});
|
||||
@ -129,7 +129,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
function testWhenOnExceptionFailedPromise() {
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$failer(new \RuntimeException);
|
||||
$promise->when(function ($e) use (&$invoked) {
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "RuntimeException");
|
||||
$invoked = true;
|
||||
});
|
||||
@ -140,22 +140,22 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$invoked = 0;
|
||||
|
||||
$promise->when(function ($e) use (&$invoked) {
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "RuntimeException");
|
||||
$invoked++;
|
||||
});
|
||||
$promise->when(function ($e) use (&$invoked) {
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "RuntimeException");
|
||||
$invoked++;
|
||||
});
|
||||
|
||||
$failer(new \RuntimeException);
|
||||
|
||||
$promise->when(function ($e) use (&$invoked) {
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "RuntimeException");
|
||||
$invoked++;
|
||||
});
|
||||
$promise->when(function ($e) use (&$invoked) {
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "RuntimeException");
|
||||
$invoked++;
|
||||
});
|
||||
@ -169,7 +169,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
}
|
||||
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$promise->when(function ($e) use (&$invoked) {
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "Error");
|
||||
$invoked = true;
|
||||
});
|
||||
@ -184,7 +184,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$failer(new \Error);
|
||||
$promise->when(function ($e) use (&$invoked) {
|
||||
$promise->onResolve(function ($e) use (&$invoked) {
|
||||
$this->assertSame(get_class($e), "Error");
|
||||
$invoked = true;
|
||||
});
|
||||
@ -207,7 +207,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
$ex = true;
|
||||
}
|
||||
if (!$ex) {
|
||||
$promise->when(function ($e, $v) use (&$invoked) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked) {
|
||||
$invoked = true;
|
||||
$this->assertFalse($v instanceof Promise);
|
||||
});
|
||||
@ -225,7 +225,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
list($promise, $succeeder) = $this->promise();
|
||||
$succeeder(true);
|
||||
$promise->when(function ($e, $v) use (&$invoked, $promise) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked, $promise) {
|
||||
$this->assertSame(null, $e);
|
||||
$this->assertSame(true, $v);
|
||||
$invoked++;
|
||||
@ -234,7 +234,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
});
|
||||
|
||||
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(true, $v);
|
||||
$invoked++;
|
||||
@ -256,14 +256,14 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
});
|
||||
|
||||
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(true, $v);
|
||||
$invoked++;
|
||||
|
||||
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(true, $v);
|
||||
$invoked++;
|
||||
@ -284,7 +284,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$exception = new \Exception;
|
||||
$failer($exception);
|
||||
$promise->when(function ($e, $v) use (&$invoked, $exception) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked, $exception) {
|
||||
$this->assertSame($exception, $e);
|
||||
$this->assertNull($v);
|
||||
$invoked++;
|
||||
@ -294,7 +294,7 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
list($promise, , $failer) = $this->promise();
|
||||
$exception = new \Exception;
|
||||
$promise->when(function ($e, $v) use (&$invoked, $exception) {
|
||||
$promise->onResolve(function ($e, $v) use (&$invoked, $exception) {
|
||||
$this->assertSame($exception, $e);
|
||||
$this->assertNull($v);
|
||||
$invoked++;
|
||||
@ -316,12 +316,12 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$expectedData = "15.24";
|
||||
|
||||
$promise->when(function($e, int $v) use (&$invoked, $expectedData) {
|
||||
$promise->onResolve(function($e, int $v) use (&$invoked, $expectedData) {
|
||||
$invoked++;
|
||||
$this->assertSame((int) $expectedData, $v);
|
||||
});
|
||||
$succeeder($expectedData);
|
||||
$promise->when(function($e, int $v) use (&$invoked, $expectedData) {
|
||||
$promise->onResolve(function($e, int $v) use (&$invoked, $expectedData) {
|
||||
$invoked++;
|
||||
$this->assertSame((int) $expectedData, $v);
|
||||
});
|
||||
@ -334,9 +334,9 @@ class PromiseTest extends \PHPUnit\Framework\TestCase {
|
||||
$invoked = false;
|
||||
|
||||
$promise = new Promise;
|
||||
$promise->when(function () { });
|
||||
$promise->when(function () { });
|
||||
$promise->when(function () use (&$invoked) {
|
||||
$promise->onResolve(function () { });
|
||||
$promise->onResolve(function () { });
|
||||
$promise->onResolve(function () use (&$invoked) {
|
||||
$invoked = true;
|
||||
$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) {
|
||||
$p = new Promise;
|
||||
$p->when(function () { });
|
||||
$p->when(function () { });
|
||||
$p->onResolve(function () { });
|
||||
$p->onResolve(function () { });
|
||||
|
||||
$last->resolve($p);
|
||||
$last = $p;
|
||||
|
@ -21,7 +21,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\some($promises)->when($callback);
|
||||
Promise\some($promises)->onResolve($callback);
|
||||
|
||||
$this->assertSame([[], [1, 2, 3]], $result);
|
||||
}
|
||||
@ -34,7 +34,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
Promise\some($promises)->when($callback);
|
||||
Promise\some($promises)->onResolve($callback);
|
||||
|
||||
$this->assertInstanceOf(MultiReasonException::class, $reason);
|
||||
$this->assertEquals([$exception, $exception, $exception], $reason->getReasons());
|
||||
@ -48,7 +48,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\some($promises)->when($callback);
|
||||
Promise\some($promises)->onResolve($callback);
|
||||
|
||||
$this->assertSame([[0 => $exception, 1 => $exception], [2 => 3]], $result);
|
||||
}
|
||||
@ -65,7 +65,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\some($promises)->when($callback);
|
||||
Promise\some($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals([[], [0 => 1, 1 => 2, 2 => 3]], $result);
|
||||
@ -85,7 +85,7 @@ class SomeTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
Promise\some($promises)->when($callback);
|
||||
Promise\some($promises)->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
@ -31,7 +31,7 @@ class StreamFromIterableTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -51,7 +51,7 @@ class StreamFromIterableTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame(\range(1, 2), $results);
|
||||
|
@ -50,7 +50,7 @@ class StreamMapTest extends \PHPUnit\Framework\TestCase {
|
||||
$results[] = $value;
|
||||
});
|
||||
|
||||
$stream->when(function ($exception, $value) use (&$result) {
|
||||
$stream->onResolve(function ($exception, $value) use (&$result) {
|
||||
$result = $value;
|
||||
});
|
||||
});
|
||||
@ -85,7 +85,7 @@ class StreamMapTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame($exception, $reason);
|
||||
@ -121,7 +121,7 @@ class StreamMapTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame(\count($values), $count);
|
||||
@ -145,7 +145,7 @@ class StreamMapTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$stream->when($callback);
|
||||
$stream->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertFalse($invoked);
|
||||
|
@ -25,7 +25,7 @@ class SuccessTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$success = new Success($value);
|
||||
|
||||
$success->when($callback);
|
||||
$success->onResolve($callback);
|
||||
|
||||
$this->assertSame(1, $invoked);
|
||||
$this->assertSame($value, $result);
|
||||
@ -50,7 +50,7 @@ class SuccessTest extends \PHPUnit\Framework\TestCase {
|
||||
|
||||
$success = new Success;
|
||||
|
||||
$success->when($callback);
|
||||
$success->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame(1, $invoked);
|
||||
|
@ -23,7 +23,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertSame($value, $result);
|
||||
});
|
||||
@ -42,7 +42,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertSame($exception, $reason);
|
||||
});
|
||||
@ -64,7 +64,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertSame($value, $result);
|
||||
@ -84,7 +84,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
$reason = $exception;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
});
|
||||
|
||||
$this->assertInstanceOf(\Amp\TimeoutException::class, $reason);
|
||||
@ -106,7 +106,7 @@ class TimeoutTest extends \PHPUnit\Framework\TestCase {
|
||||
$result = $value;
|
||||
};
|
||||
|
||||
$promise->when($callback);
|
||||
$promise->onResolve($callback);
|
||||
|
||||
$this->assertSame($value, $result);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user