Skip to content

Commit 4886ff8

Browse files
committed
Added error and stream completion notice
1 parent b12bcf3 commit 4886ff8

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

examples/profile-update-username-on-tweet-async.php

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,30 @@
3434
return $resource instanceof Tweet;
3535
})->filter(function (Tweet $tweet) use ($profile) {
3636
return $tweet->user()->idStr() === $profile->idStr();
37-
})->subscribeCallback(function (Tweet $tweet) use ($profile, $argv, $emojis) {
38-
echo '------------------', PHP_EOL;
39-
echo $tweet->text(), PHP_EOL;
40-
echo '------------------', PHP_EOL;
41-
$profile = $profile->withName(sprintf(
42-
$argv[1],
43-
$emojis[random_int(0, count($emojis) - 1)]
44-
));
45-
$profile->putProfile()->done(function (ProfileInterface $newProfile) use ($profile) {
46-
$profile = $newProfile;
47-
resource_pretty_print($profile);
48-
});
49-
});
37+
})->subscribeCallback(
38+
function (Tweet $tweet) use ($profile, $argv, $emojis) {
39+
echo '------------------', PHP_EOL;
40+
echo $tweet->text(), PHP_EOL;
41+
echo '------------------', PHP_EOL;
42+
$profile = $profile->withName(sprintf(
43+
$argv[1],
44+
$emojis[random_int(0, count($emojis) - 1)]
45+
));
46+
$profile->putProfile()->done(function (ProfileInterface $newProfile) use ($profile) {
47+
$profile = $newProfile;
48+
resource_pretty_print($profile);
49+
});
50+
},
51+
function ($e) {
52+
echo (string)$e;
53+
},
54+
function () {
55+
echo PHP_EOL;
56+
echo '------------------', PHP_EOL;
57+
echo 'Completed streaming', PHP_EOL;
58+
echo '------------------', PHP_EOL;
59+
}
60+
);
5061
});
5162

5263
$loop->run();

0 commit comments

Comments
 (0)