diff --git a/README.md b/README.md index 7fe9af6..bc883f2 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ This project provides a *simple* API for invoking *async* RPCs to remote web ser * [getLocation()](#getlocation) * [Proxy](#proxy) * [Functions](#functions) - * [Processing](#processing) + * [Promises](#promises) + * [Cancellation](#cancellation) * [Install](#install) * [Tests](#tests) * [License](#license) @@ -209,7 +210,7 @@ $proxy->myMethod($myArg1, $myArg2)->then(function ($response) { Please refer to your WSDL or its accompanying documentation for details on which functions and arguments are supported. -#### Processing +#### Promises Issuing SOAP functions is async (non-blocking), so you can actually send multiple RPC requests in parallel. The web service will respond to each request with a return value. The order is not guaranteed. @@ -227,6 +228,21 @@ $proxy->demo()->then( }); ``` +#### Cancellation + +The returned Promise is implemented in such a way that it can be cancelled +when it is still pending. +Cancelling a pending promise will reject its value with an Exception and +clean up any underlying resources. + +```php +$promise = $proxy->demo(); + +$loop->addTimer(2.0, function () use ($promise) { + $promise->cancel(); +}); +``` + ## Install The recommended way to install this library is [through Composer](https://getcomposer.org). diff --git a/composer.json b/composer.json index 1471ac9..33ea0da 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,9 @@ }, "require": { "php": ">=5.3", - "clue/buzz-react": "^2.0 || ^1.0", + "clue/buzz-react": "^2.0 || ^1.3", "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3", - "react/promise": "~1.0|~2.0", + "react/promise": "^2.1 || ^1.2", "ext-soap": "*" }, "require-dev": { diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 1b0b16f..15ef710 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -70,6 +70,32 @@ public function testBlzServiceWithInvalidMethod() Block\await($promise, $this->loop); } + /** + * @expectedException Exception + */ + public function testCancelCreateClientRejects() + { + $factory = new Factory($this->loop); + + $promise = $factory->createClient('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl'); + $promise->cancel(); + + Block\await($promise, $this->loop); + } + + /** + * @expectedException Exception + */ + public function testCancelMethodRejects() + { + $api = new Proxy($this->client); + + $promise = $api->getBank(array('blz' => '12070000')); + $promise->cancel(); + + Block\await($promise, $this->loop); + } + public function testGetLocationForFunctionName() { $this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation('getBank'));