mirror of
https://github.com/danog/amp.git
synced 2024-11-26 20:15:00 +01:00
Rename createRunnable to asyncCoroutine and createCallable to coroutine
This commit is contained in:
parent
05670678e1
commit
e9d48a68d5
@ -6,7 +6,7 @@ namespace Amp {
|
||||
/**
|
||||
* Returns a new function that wraps $callback in a promise/coroutine-aware function that automatically runs
|
||||
* Generators as coroutines. The returned function always returns void when invoked. Errors are forwarded to the
|
||||
* loop error handler using `Amp\Promise\rethrow()`.
|
||||
* loop's error handler using `Amp\Promise\rethrow()`.
|
||||
*
|
||||
* Use this function to create a coroutine-aware callable for a non-promise-aware callback caller.
|
||||
*
|
||||
@ -14,9 +14,9 @@ namespace Amp {
|
||||
*
|
||||
* @return callable(...$args): void
|
||||
*
|
||||
* @see createCallable()
|
||||
* @see coroutine()
|
||||
*/
|
||||
function createRunnable(callable $callback): callable {
|
||||
function asyncCoroutine(callable $callback): callable {
|
||||
return function (...$args) use ($callback) {
|
||||
Promise\rethrow(call($callback, ...$args));
|
||||
};
|
||||
@ -33,9 +33,9 @@ namespace Amp {
|
||||
*
|
||||
* @return callable(mixed ...$args): \Amp\Promise
|
||||
*
|
||||
* @see createRunnable()
|
||||
* @see asyncCoroutine()
|
||||
*/
|
||||
function createCallable(callable $callback): callable {
|
||||
function coroutine(callable $callback): callable {
|
||||
return function (...$args) use ($callback): Promise {
|
||||
return call($callback, ...$args);
|
||||
};
|
||||
|
@ -449,8 +449,8 @@ class CoroutineTest extends TestCase {
|
||||
$this->assertTrue($invoked);
|
||||
}
|
||||
|
||||
public function testCreateCallableFunction() {
|
||||
$callable = \Amp\createCallable(function () {
|
||||
public function testCoroutineFunction() {
|
||||
$callable = \Amp\coroutine(function () {
|
||||
yield;
|
||||
});
|
||||
|
||||
@ -458,12 +458,12 @@ class CoroutineTest extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCallableFunction
|
||||
* @depends testCoroutineFunction
|
||||
*/
|
||||
public function testCreateCallableFunctionWithCallbackReturningPromise() {
|
||||
public function testCoroutineFunctionWithCallbackReturningPromise() {
|
||||
$value = 1;
|
||||
$promise = new Success($value);
|
||||
$callable = \Amp\createCallable(function ($value) {
|
||||
$callable = \Amp\coroutine(function ($value) {
|
||||
return $value;
|
||||
});
|
||||
|
||||
@ -482,11 +482,11 @@ class CoroutineTest extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCallableFunction
|
||||
* @depends testCoroutineFunction
|
||||
*/
|
||||
public function testCreateCallableFunctionWithNonGeneratorCallback() {
|
||||
public function testCoroutineFunctionWithNonGeneratorCallback() {
|
||||
$value = 1;
|
||||
$callable = \Amp\createCallable(function ($value) {
|
||||
$callable = \Amp\coroutine(function ($value) {
|
||||
return $value;
|
||||
});
|
||||
|
||||
@ -505,11 +505,11 @@ class CoroutineTest extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCallableFunction
|
||||
* @depends testCoroutineFunction
|
||||
*/
|
||||
public function testCreateCallableFunctionWithThrowingCallback() {
|
||||
public function testCoroutineFunctionWithThrowingCallback() {
|
||||
$exception = new \Exception;
|
||||
$callable = \Amp\createCallable(function () use ($exception) {
|
||||
$callable = \Amp\coroutine(function () use ($exception) {
|
||||
throw $exception;
|
||||
});
|
||||
|
||||
@ -528,10 +528,10 @@ class CoroutineTest extends TestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCallableFunction
|
||||
* @depends testCoroutineFunction
|
||||
*/
|
||||
public function testCreateCallableFunctionWithSuccessReturnCallback() {
|
||||
$callable = \Amp\createCallable(function () {
|
||||
public function testCoroutineFunctionWithSuccessReturnCallback() {
|
||||
$callable = \Amp\coroutine(function () {
|
||||
return new Success(42);
|
||||
});
|
||||
|
||||
@ -549,8 +549,8 @@ class CoroutineTest extends TestCase {
|
||||
$this->assertSame(42, $result);
|
||||
}
|
||||
|
||||
public function testCreateCallableFunctionWithReactPromise() {
|
||||
$callable = \Amp\createCallable(function () {
|
||||
public function testCoroutineFunctionWithReactPromise() {
|
||||
$callable = \Amp\coroutine(function () {
|
||||
return new FulfilledReactPromise(42);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user