-
Notifications
You must be signed in to change notification settings - Fork 0
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
b956ec6
commit f7c4732
Showing
8 changed files
with
39 additions
and
63 deletions.
There are no files selected for viewing
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
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
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,24 @@ | ||
fn foo(a) { | ||
print("foo 函数输出", a) | ||
rt sync.yield(2 * a) // 返回 2*a 的值 | ||
} | ||
|
||
co = sync.create(fn (a , b) { | ||
print("第一次协同程序执行输出", a, b) // co-body 1 10 | ||
shy r = foo(a + 1) | ||
|
||
print("第二次协同程序执行输出", r) | ||
shy r, s = sync.yield(a + b, a - b) // a,b的值为第一次调用协同程序时传入 | ||
|
||
print("第三次协同程序执行输出", r, s) | ||
rt b, "结束协同程序" // b的值为第二次调用协同程序时传入 | ||
}) | ||
|
||
print("main", sync.resume(co, 1, 10)) // true, 4 | ||
print() | ||
print("main", sync.resume(co, "r")) // true 11 -9 | ||
print() | ||
print("main", sync.resume(co, "x", "y")) // true 10 end | ||
print() | ||
print("main", sync.resume(co, "x", "y")) // cannot resume dead sync | ||
print() |