Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cancellation support #30

Merged
merged 1 commit into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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