Skip to content

Commit

Permalink
Fix a doc and update an example
Browse files Browse the repository at this point in the history
  • Loading branch information
m50 committed Mar 11, 2024
1 parent bdc08e7 commit a3ee825
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
21 changes: 16 additions & 5 deletions examples/subscribe-and-unsubscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@
use m50\Pusher\Client;
use m50\Pusher\Event;

use function Amp\async;
use function Amp\delay;

include_once('vendor/autoload.php');

$client = Client::create('my-app', 'us3');

$channel = $client->channel('my-channel');
$channel->subscribe(function (Event $event) use ($channel) {
var_dump($event);
if ($event->event === 'END') {
$channel->unsubscribe();
}
async(function () use ($channel) {
echo 'in async' . PHP_EOL;
$channel->subscribe(function (Event $event) use ($channel) {
var_dump($event);
if ($event->event === 'END') {
$channel->unsubscribe();
}
});
});

delay(30);
echo 'delayed' . PHP_EOL;
$client->close();
echo 'closed' . PHP_EOL;
3 changes: 2 additions & 1 deletion src/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function unsubscribe()
/**
* Execute an action on every event that belongs to the channel.
*
* @param (callable(Event $event): void) $onEvent
* @param (callable(Event): void) $onEvent
* @param (callable(\Throwable): void) $onError
* @return void
*/
public function subscribe(callable $onEvent, ?callable $onError = null): void
Expand Down

0 comments on commit a3ee825

Please sign in to comment.