From e9d48a68d5edb6d67e90fb8d10214a6ce9d7d3b3 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Sun, 23 Apr 2017 20:07:06 +0200 Subject: [PATCH] Rename createRunnable to asyncCoroutine and createCallable to coroutine --- lib/functions.php | 10 +++++----- test/CoroutineTest.php | 32 ++++++++++++++++---------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/functions.php b/lib/functions.php index b826fcf..c66ee24 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -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); }; diff --git a/test/CoroutineTest.php b/test/CoroutineTest.php index ff1dd1c..a3b35c8 100644 --- a/test/CoroutineTest.php +++ b/test/CoroutineTest.php @@ -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); });