Skip to content

Commit

Permalink
Merge pull request #30 from clue-labs/cancellation
Browse files Browse the repository at this point in the history
Add cancellation support
  • Loading branch information
clue authored Sep 10, 2018
2 parents 1cebcb3 + 7d6ed98 commit 54eea46
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
26 changes: 26 additions & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 54eea46

Please sign in to comment.