221V 2 weeks ago
parent
commit
9bb5785611
3 changed files with 53 additions and 7 deletions
  1. 10 2
      vtest2/source/app.d
  2. 0 5
      vtest2/source/test5.d
  3. 43 0
      vtest2/source/test6.d

+ 10 - 2
vtest2/source/app.d

@@ -39,11 +39,18 @@ import std.concurrency : spawn;
 import test4 : test4_spawner;
 */
 
-
+/*
 // test5
 import std.concurrency : spawn;
 
 import test5 : test5_spawner;
+*/
+
+
+// test6
+import std.concurrency : spawn;
+
+import test6 : test6_spawner;
 
 
 void main(){
@@ -51,7 +58,8 @@ void main(){
   //spawn(&test2_spawner); // test2 run
   //spawn(&test3_spawner); // test3 run
   //spawn(&test4_spawner); // test4 run
-  spawn(&test5_spawner); // test5 run
+  //spawn(&test5_spawner); // test5 run
+  spawn(&test6_spawner); // test6 run
   
   //Thread.sleep(dur!"seconds"(125));
   //Thread.sleep(dur!"seconds"(3));

+ 0 - 5
vtest2/source/test5.d

@@ -1,9 +1,4 @@
 
-// todo test
-// https://chat.qwen.ai/c/b2eea389-4859-4467-aa24-85e189a4557e
-// https://chat.qwen.ai/c/5cfd2bc3-66eb-4ca5-a2cd-7126e99e4dc4
-// https://vibed.org/api/vibe.core.channel/
-
 import std.stdio;
 
 import core.thread : Fiber;

+ 43 - 0
vtest2/source/test6.d

@@ -0,0 +1,43 @@
+
+import std.stdio;
+
+import core.thread : Fiber;
+
+
+void fib(ref int current){
+  current = 0;
+  int next = 1;
+  
+  while(true){
+    Fiber.yield();
+    
+    const next2 = current + next;
+    current = next;
+    next = next2;
+  }
+}
+
+
+void test6_spawner(){
+  int current;
+  
+  Fiber fiber = new Fiber(() => fib(current));
+  
+  int i = 0;
+  while(i < 10){
+    fiber.call();
+    
+    writef("%s ", current);
+    i++;
+  }
+  
+}
+
+/*
+
+./vtest2
+hello here!
+0 1 1 2 3 5 8 13 21 34
+
+*/
+