Skip to content

Commit 4fa7398

Browse files
committed
docs(readme): add coroutine handler example
- Added a new code snippet for setting a coroutine handler in the client. - This example demonstrates how to use the CoroutineHandler with Hyperf Guzzle. - Provides clarity on handling asynchronous requests in the documentation.
1 parent 8195dde commit 4fa7398

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,28 @@ $response = $promise->wait();
136136
$responses = $client->pool($messages);
137137
```
138138

139+
### Hyperf integration
140+
141+
```php
142+
use Guanguans\Notify\Foundation\Client;
143+
use Guanguans\Notify\Foundation\Middleware\Authenticate;
144+
use Guanguans\Notify\Foundation\Middleware\Response;
145+
use Hyperf\Guzzle\CoroutineHandler;
146+
use Hyperf\Guzzle\HandlerStackFactory;
147+
148+
// Set Handler directly
149+
$client->setHandler(new CoroutineHandler);
150+
151+
// Or set HandlerStackResolver
152+
$client->setHandlerStackResolver(static function (Client $client) {
153+
$handlerStack = (new HandlerStackFactory)->create();
154+
$handlerStack->push(new Authenticate($client->getAuthenticator()), Authenticate::class);
155+
$handlerStack->push(new Response, Response::class);
156+
157+
return $handlerStack;
158+
});
159+
```
160+
139161
### Completion
140162

141163
> [!TIP]

0 commit comments

Comments
 (0)