Created
December 21, 2022 12:09
-
-
Save GitHub30/c18d534c62b6dd3dfcba7b9b26bfaa4f to your computer and use it in GitHub Desktop.
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 | |
require __DIR__ . '/../vendor/autoload.php'; | |
use function Amp\async; | |
use function Amp\delay; | |
$array = []; | |
// deferは新しいFiberを作り、実行中のFiberが終了したら自動的に次を実行する | |
$array[] = async(function (): void { | |
delay(15); | |
var_dump(1); | |
}); | |
$array[] = async(function (): void { | |
delay(10); | |
var_dump(2); | |
}); | |
$array[] = async(function (): void { | |
delay(20); | |
var_dump(3); | |
}); | |
// メインスレッドを一時停止 | |
delay(5); | |
var_dump(4); | |
Amp\Future\await($array); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment