-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84d6a48
commit 8e571ad
Showing
16 changed files
with
285 additions
and
104 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
snap-compile/src/test/java/org/snapscript/compile/AwaitCascadeTest.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.snapscript.compile; | ||
|
||
public class AwaitCascadeTest extends ScriptTestCase { | ||
|
||
private static final String SOURCE_1 = | ||
"async func one(){\n"+ | ||
" println(`one(): ` +Thread.currentThread().getName());\n"+ | ||
" let a1 = await two();\n"+ | ||
" let b1 = await two();\n"+ | ||
" return `one: ${a1}---${b1}`;\n"+ | ||
"}\n"+ | ||
"async func two(){\n"+ | ||
" println(`two(): ` +Thread.currentThread().getName());\n"+ | ||
" let a2 = await three();\n"+ | ||
" return `two: ${a2}`;\n"+ | ||
"}\n"+ | ||
"async func three(){\n"+ | ||
" println(`three(): ` +Thread.currentThread().getName());\n"+ | ||
" let a3 = await 'foo'.toUpperCase();\n"+ | ||
" return `three: ${a3}`;\n"+ | ||
"}\n"+ | ||
"one().join().success(this::println);\n"+ | ||
"one().join().success(result -> {\n"+ | ||
" assert result == 'one: two: three: FOO---two: three: FOO';\n"+ | ||
"});\n"; | ||
|
||
private static final String SOURCE_2 = | ||
"async func one(n){\n"+ | ||
" if(n > 0) {\n"+ | ||
" println(`two(${n}): ` +Thread.currentThread().getName());\n"+ | ||
" await two(n-1);\n"+ | ||
" }\n"+ | ||
" return 'one';\n"+ | ||
"}\n"+ | ||
"\n"+ | ||
"async func two(n){\n"+ | ||
" if(n > 0) {\n"+ | ||
" println(`one(${n}): ` +Thread.currentThread().getName());\n"+ | ||
" await one(n-1);\n"+ | ||
" }\n"+ | ||
" return 'two';\n"+ | ||
"}\n"+ | ||
"one(100).join().success(this::println);\n"; | ||
|
||
public void testAwaitCascade() throws Exception { | ||
assertScriptExecutes(SOURCE_1); | ||
assertScriptExecutes(SOURCE_2); | ||
} | ||
|
||
@Override | ||
public boolean isThreadPool() { | ||
return true; | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.snapscript.core; | ||
|
||
public interface Answer { | ||
void success(Object value); | ||
void failure(Throwable cause); | ||
} |
Oops, something went wrong.