Skip to content

Commit

Permalink
update uv_queue_work() examples
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Mar 16, 2023
1 parent bc87d99 commit 6296fc4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/uv/queue_2_threads.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
uv_queue_work($loop, function () use (&$completed) {
while (!$completed) {
echo "[queue2]";
sleep(1);
usleep(1);
}
}, function () {
echo "[finished]";
Expand All @@ -15,7 +15,7 @@
while (!$completed) {
echo "[queue1]";
$completed = true;
sleep(1);
usleep(2);
}
}, function () {
echo "[finished]";
Expand Down
3 changes: 1 addition & 2 deletions examples/uv/queue_channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$function = function () use ($write) {
echo "[queue1]";
\fwrite($write, "Thread 1\n");
\sleep(1);
\usleep(1);
};

\uv_queue_work($loop, $function, function () {
Expand All @@ -22,4 +22,3 @@

\uv_run($loop);
\fclose($write);
\fclose($read);
28 changes: 28 additions & 0 deletions examples/uv/uv_queue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

$loop = uv_default_loop();

$thread = function () {
echo "THREAD-CALL\n";
};

$after = function () {
echo "THREAD-CALL-AFTER\n";
};

uv_queue_work($loop, $thread, $after);
uv_queue_work($loop, $thread, $after);

$timer = uv_timer_init($loop);

uv_timer_start($timer, 1000, 1000, function ($time) {
static $i = 0;

echo "TIMER: $i\n";

$i++;
if ($i === 11)
uv_timer_stop($time);
});

uv_run($loop);

0 comments on commit 6296fc4

Please sign in to comment.