Skip to content

Commit 4cb87d7

Browse files
committed
No need to assign the function to a $variable, just pass it into the observer right away
1 parent 1cf9ce6 commit 4cb87d7

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

examples/reddit.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77

88
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
99

10-
$display = function ($event) {
11-
echo 'Channel: ', $event['channel'], PHP_EOL;
12-
echo 'Event: ', $event['event'], PHP_EOL;
13-
echo 'Data: ', $event['data'], PHP_EOL;
14-
};
15-
1610
$loop = Factory::create();
1711

1812
/**
@@ -24,7 +18,11 @@
2418
$subReddits = $argv;
2519
array_shift($subReddits);
2620
foreach ($subReddits as $subReddit) {
27-
$client->subscribe($subReddit)->subscribe(new CallbackObserver($display));
21+
$client->subscribe($subReddit)->subscribe(new CallbackObserver(function($event) {
22+
echo 'Channel: ', $event['channel'], PHP_EOL;
23+
echo 'Event: ', $event['event'], PHP_EOL;
24+
echo 'Data: ', $event['data'], PHP_EOL;
25+
}));
2826
}
2927

3028
$loop->run();

0 commit comments

Comments
 (0)