You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70Lines changed: 70 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,8 @@ enriched with the comfort of [ReactPHP's Promises](https://github.com/reactphp/p
18
18
*[Usage](#usage)
19
19
*[Client](#client)
20
20
*[Promises](#promises)
21
+
*[Cancellation](#cancellation)
22
+
*[Timeouts](#timeouts)
21
23
*[search()](#search)
22
24
*[get()](#get)
23
25
*[all()](#all)
@@ -92,6 +94,68 @@ Sending requests is async (non-blocking), so you can actually send multiple requ
92
94
Packagist will respond to each request with a response message, the order is not guaranteed.
93
95
Sending requests uses a [Promise](https://github.com/reactphp/promise)-based interface that makes it easy to react to when a request is fulfilled (i.e. either successfully resolved or rejected with an error).
94
96
97
+
```php
98
+
$client->get('clue/graph-composer')->then(
99
+
function ($result) {
100
+
// result received for get() function
101
+
},
102
+
function (Exception $e) {
103
+
// an error occured while executing the request
104
+
}
105
+
});
106
+
```
107
+
108
+
#### Cancellation
109
+
110
+
The returned Promise is implemented in such a way that it can be cancelled
111
+
when it is still pending.
112
+
Cancelling a pending promise will reject its value with an Exception and
113
+
clean up any underlying resources.
114
+
115
+
```php
116
+
$promise = $client->get('clue/graph-composer');
117
+
118
+
$loop->addTimer(2.0, function () use ($promise) {
119
+
$promise->cancel();
120
+
});
121
+
```
122
+
123
+
#### Timeouts
124
+
125
+
This library uses a very efficient HTTP implementation, so most API requests
126
+
should usually be completed in mere milliseconds. However, when sending API
127
+
requests over an unreliable network (the internet), there are a number of things
128
+
that can go wrong and may cause the request to fail after a time. As such,
129
+
timeouts are handled by the underlying HTTP library and this library respects
130
+
PHP's `default_socket_timeout` setting (default 60s) as a timeout for sending the
131
+
outgoing API request and waiting for a successful response and will otherwise
132
+
cancel the pending request and reject its value with an Exception.
133
+
134
+
Note that this timeout value covers creating the underlying transport connection,
135
+
sending the API request, waiting for the Packagist service to process the request
136
+
and receiving the full API response. To pass a custom timeout value, you can
137
+
assign the underlying [`timeout` option](https://github.com/clue/reactphp-buzz#timeouts)
0 commit comments