test6.d 473 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import std.stdio;
  2. import core.thread : Fiber;
  3. void fib(ref int current){
  4. current = 0;
  5. int next = 1;
  6. while(true){
  7. Fiber.yield();
  8. const next2 = current + next;
  9. current = next;
  10. next = next2;
  11. }
  12. }
  13. void test6_spawner(){
  14. int current;
  15. Fiber fiber = new Fiber(() => fib(current));
  16. int i = 0;
  17. while(i < 10){
  18. fiber.call();
  19. writef("%s ", current);
  20. i++;
  21. }
  22. }
  23. /*
  24. ./vtest2
  25. hello here!
  26. 0 1 1 2 3 5 8 13 21 34
  27. */