Browse Source

test9 - vibed async task

221V 2 weeks ago
parent
commit
0155ecf076
2 changed files with 52 additions and 2 deletions
  1. 11 2
      vtest2/source/app.d
  2. 41 0
      vtest2/source/test9.d

+ 11 - 2
vtest2/source/app.d

@@ -62,10 +62,18 @@ import test7 : test7_spawner;
 */
 
 
-// test8
+/*
+// test8 - vibed async task
 import std.concurrency : spawn;
 
 import test8 : test8_spawner;
+*/
+
+
+// test9 - vibed async task
+import std.concurrency : spawn;
+
+import test9 : test9_spawner;
 
 
 void main(){
@@ -76,7 +84,8 @@ void main(){
   //spawn(&test5_spawner); // test5 run
   //spawn(&test6_spawner); // test6 run
   //spawn(&test7_spawner); // test7 run
-  spawn(&test8_spawner); // test8 run
+  //spawn(&test8_spawner); // test8 run
+  spawn(&test9_spawner); // test9 run
   
   //Thread.sleep(dur!"seconds"(125));
   //Thread.sleep(dur!"seconds"(3));

+ 41 - 0
vtest2/source/test9.d

@@ -0,0 +1,41 @@
+
+
+import std.stdio;
+
+import core.time : dur;
+
+import vibe.core.core;
+import vibe.core.concurrency;
+
+
+int sum(int a, int b){
+  return a + b;
+}
+
+static int sum2(int a, int b){
+  return a + b;
+}
+
+
+void test9_spawner(){
+  //assert(async(&sum, 2, 3).getResult() == 5);
+  //assert(async(&sum2, 2, 3).getResult() == 5);
+  
+  auto v1 = async(&sum, 2, 3);
+  writeln("v1 = ", v1.getResult());
+  assert(v1 == 5);
+  
+  int v2 = async(&sum2, 2, 3).getResult();
+  writeln("v2 = ", v2);
+  assert(v2 == 5);
+}
+
+/*
+
+./vtest2
+hello here!
+v1 = 5
+v2 = 5
+
+*/
+