Skip to content

Commit 7d6ed98

Browse files
committed
Add cancellation support
Builds on top of clue/reactphp-buzz#75
1 parent 355bafb commit 7d6ed98

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ This project provides a *simple* API for invoking *async* RPCs to remote web ser
4242
* [getLocation()](#getlocation)
4343
* [Proxy](#proxy)
4444
* [Functions](#functions)
45-
* [Processing](#processing)
45+
* [Promises](#promises)
46+
* [Cancellation](#cancellation)
4647
* [Install](#install)
4748
* [Tests](#tests)
4849
* [License](#license)
@@ -209,7 +210,7 @@ $proxy->myMethod($myArg1, $myArg2)->then(function ($response) {
209210
Please refer to your WSDL or its accompanying documentation for details
210211
on which functions and arguments are supported.
211212

212-
#### Processing
213+
#### Promises
213214

214215
Issuing SOAP functions is async (non-blocking), so you can actually send multiple RPC requests in parallel.
215216
The web service will respond to each request with a return value. The order is not guaranteed.
@@ -227,6 +228,21 @@ $proxy->demo()->then(
227228
});
228229
```
229230

231+
#### Cancellation
232+
233+
The returned Promise is implemented in such a way that it can be cancelled
234+
when it is still pending.
235+
Cancelling a pending promise will reject its value with an Exception and
236+
clean up any underlying resources.
237+
238+
```php
239+
$promise = $proxy->demo();
240+
241+
$loop->addTimer(2.0, function () use ($promise) {
242+
$promise->cancel();
243+
});
244+
```
245+
230246
## Install
231247

232248
The recommended way to install this library is [through Composer](https://getcomposer.org).

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
},
1616
"require": {
1717
"php": ">=5.3",
18-
"clue/buzz-react": "^2.0 || ^1.0",
18+
"clue/buzz-react": "^2.0 || ^1.3",
1919
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
20-
"react/promise": "~1.0|~2.0",
20+
"react/promise": "^2.1 || ^1.2",
2121
"ext-soap": "*"
2222
},
2323
"require-dev": {

tests/FunctionalTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,32 @@ public function testBlzServiceWithInvalidMethod()
7070
Block\await($promise, $this->loop);
7171
}
7272

73+
/**
74+
* @expectedException Exception
75+
*/
76+
public function testCancelCreateClientRejects()
77+
{
78+
$factory = new Factory($this->loop);
79+
80+
$promise = $factory->createClient('http://www.thomas-bayer.com/axis2/services/BLZService?wsdl');
81+
$promise->cancel();
82+
83+
Block\await($promise, $this->loop);
84+
}
85+
86+
/**
87+
* @expectedException Exception
88+
*/
89+
public function testCancelMethodRejects()
90+
{
91+
$api = new Proxy($this->client);
92+
93+
$promise = $api->getBank(array('blz' => '12070000'));
94+
$promise->cancel();
95+
96+
Block\await($promise, $this->loop);
97+
}
98+
7399
public function testGetLocationForFunctionName()
74100
{
75101
$this->assertEquals('http://www.thomas-bayer.com/axis2/services/BLZService', $this->client->getLocation('getBank'));

0 commit comments

Comments
 (0)