Last active
July 6, 2022 00:16
-
-
Save iberflow/0d685a279fa5f49674d0407a5a51ce23 to your computer and use it in GitHub Desktop.
Swoole coroutines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Swoole\Coroutine as Co; | |
Co\run(function () { | |
for ($i = 0; $i < 100; $i++) { | |
go(function () use($i) { | |
usleep(1_000_00 * mt_rand(1,10)); | |
echo "Coroutine $i is done.\n"; | |
}); | |
} | |
}); | |
echo "Outside any Coroutine Context.\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment