resume003.php 556 B

123456789101112131415161718192021222324
  1. <?php
  2. go(function () {
  3. $count = 0;
  4. go(function () use (&$count) {
  5. echo "task 1 start\n";
  6. co::sleep(0.2);
  7. echo "task 1 resume count $count\n";
  8. if (++$count === 2) {
  9. co::resume(1);
  10. }
  11. echo "task 1 end\n";
  12. });
  13. go(function () use (&$count) {
  14. echo "task 2 start\n";
  15. co::sleep(0.1);
  16. echo "task 2 resume count $count\n";
  17. if (++$count === 2) {
  18. co::resume(1);
  19. }
  20. echo "task 2 end\n";
  21. });
  22. co::suspend();
  23. });
  24. echo "main \n";