動き yieldによって重い処理は実行そのものは一旦置いておいて、$taskに追加されていく Co::waitによって一斉開始 すべての処理が終了したあと(上では15秒後が)以降の処理が進む
Last active
March 23, 2018 14:39
-
-
Save zinntikumugai/7bdaf3c1d5404b9e911562de3c7db6eb to your computer and use it in GitHub Desktop.
mpyw/Coテスト
This file contains 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
vendor | |
composer.lock |
This file contains 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
{ | |
"require": { | |
"mpyw/co": "^1.5" | |
} | |
} |
This file contains 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_once __DIR__ .'/vendor/autoload.php'; | |
$task = []; | |
$runs = [ | |
1, | |
2, | |
5, | |
10, | |
15, | |
10, | |
15 | |
]; | |
foreach($runs as $run) { | |
$task[] = function() use($run) { | |
echo "running {$run} Start" .PHP_EOL; | |
yield mpyw\Co\Co::DELAY => $run; //なんか知らんがsleepは対応してないらしい | |
echo "running {$run} Done." .PHP_EOL; | |
return $run; | |
}; | |
} | |
echo "Running!" .PHP_EOL; | |
var_dump(mpyw\Co\Co::wait($task)); | |
echo "End!" .PHP_EOL; | |
/* | |
動き | |
yieldによって重い処理は実行そのものは一旦置いておいて、$taskに追加されていく | |
Co::waitによって一斉開始 | |
すべての処理が終了したあと(上では15秒後が)以降の処理が進む | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment