Skip to content

Instantly share code, notes, and snippets.

@GitHub30
Created December 21, 2022 12:09
Show Gist options
  • Save GitHub30/c18d534c62b6dd3dfcba7b9b26bfaa4f to your computer and use it in GitHub Desktop.
Save GitHub30/c18d534c62b6dd3dfcba7b9b26bfaa4f to your computer and use it in GitHub Desktop.
<?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