Skip to content

Commit

Permalink
docs(readme): add coroutine handler example
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
guanguans committed Sep 9, 2024
1 parent 8195dde commit 4fa7398
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ $response = $promise->wait();
$responses = $client->pool($messages);
```

### Hyperf integration

```php
use Guanguans\Notify\Foundation\Client;
use Guanguans\Notify\Foundation\Middleware\Authenticate;
use Guanguans\Notify\Foundation\Middleware\Response;
use Hyperf\Guzzle\CoroutineHandler;
use Hyperf\Guzzle\HandlerStackFactory;

// Set Handler directly
$client->setHandler(new CoroutineHandler);

// Or set HandlerStackResolver
$client->setHandlerStackResolver(static function (Client $client) {
$handlerStack = (new HandlerStackFactory)->create();
$handlerStack->push(new Authenticate($client->getAuthenticator()), Authenticate::class);
$handlerStack->push(new Response, Response::class);

return $handlerStack;
});
```

### Completion

> [!TIP]
Expand Down

0 comments on commit 4fa7398

Please sign in to comment.