1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00

Rename createRunnable to asyncCoroutine and createCallable to coroutine

This commit is contained in:
Niklas Keller 2017-04-23 20:07:06 +02:00
parent 05670678e1
commit e9d48a68d5
2 changed files with 21 additions and 21 deletions

View File

@ -6,7 +6,7 @@ namespace Amp {
/** /**
* Returns a new function that wraps $callback in a promise/coroutine-aware function that automatically runs * 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 * 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. * 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 * @return callable(...$args): void
* *
* @see createCallable() * @see coroutine()
*/ */
function createRunnable(callable $callback): callable { function asyncCoroutine(callable $callback): callable {
return function (...$args) use ($callback) { return function (...$args) use ($callback) {
Promise\rethrow(call($callback, ...$args)); Promise\rethrow(call($callback, ...$args));
}; };
@ -33,9 +33,9 @@ namespace Amp {
* *
* @return callable(mixed ...$args): \Amp\Promise * @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 function (...$args) use ($callback): Promise {
return call($callback, ...$args); return call($callback, ...$args);
}; };

View File

@ -449,8 +449,8 @@ class CoroutineTest extends TestCase {
$this->assertTrue($invoked); $this->assertTrue($invoked);
} }
public function testCreateCallableFunction() { public function testCoroutineFunction() {
$callable = \Amp\createCallable(function () { $callable = \Amp\coroutine(function () {
yield; yield;
}); });
@ -458,12 +458,12 @@ class CoroutineTest extends TestCase {
} }
/** /**
* @depends testCreateCallableFunction * @depends testCoroutineFunction
*/ */
public function testCreateCallableFunctionWithCallbackReturningPromise() { public function testCoroutineFunctionWithCallbackReturningPromise() {
$value = 1; $value = 1;
$promise = new Success($value); $promise = new Success($value);
$callable = \Amp\createCallable(function ($value) { $callable = \Amp\coroutine(function ($value) {
return $value; return $value;
}); });
@ -482,11 +482,11 @@ class CoroutineTest extends TestCase {
} }
/** /**
* @depends testCreateCallableFunction * @depends testCoroutineFunction
*/ */
public function testCreateCallableFunctionWithNonGeneratorCallback() { public function testCoroutineFunctionWithNonGeneratorCallback() {
$value = 1; $value = 1;
$callable = \Amp\createCallable(function ($value) { $callable = \Amp\coroutine(function ($value) {
return $value; return $value;
}); });
@ -505,11 +505,11 @@ class CoroutineTest extends TestCase {
} }
/** /**
* @depends testCreateCallableFunction * @depends testCoroutineFunction
*/ */
public function testCreateCallableFunctionWithThrowingCallback() { public function testCoroutineFunctionWithThrowingCallback() {
$exception = new \Exception; $exception = new \Exception;
$callable = \Amp\createCallable(function () use ($exception) { $callable = \Amp\coroutine(function () use ($exception) {
throw $exception; throw $exception;
}); });
@ -528,10 +528,10 @@ class CoroutineTest extends TestCase {
} }
/** /**
* @depends testCreateCallableFunction * @depends testCoroutineFunction
*/ */
public function testCreateCallableFunctionWithSuccessReturnCallback() { public function testCoroutineFunctionWithSuccessReturnCallback() {
$callable = \Amp\createCallable(function () { $callable = \Amp\coroutine(function () {
return new Success(42); return new Success(42);
}); });
@ -549,8 +549,8 @@ class CoroutineTest extends TestCase {
$this->assertSame(42, $result); $this->assertSame(42, $result);
} }
public function testCreateCallableFunctionWithReactPromise() { public function testCoroutineFunctionWithReactPromise() {
$callable = \Amp\createCallable(function () { $callable = \Amp\coroutine(function () {
return new FulfilledReactPromise(42); return new FulfilledReactPromise(42);
}); });