@@ -14,7 +14,7 @@ local pong = function (thread)
1414 nxt = function (cont , ...)
1515 if not cont
1616 then return ...
17- else return nxt (co .resume (thread ) , ... )
17+ else return nxt (co .resume (thread , ... ) )
1818 end
1919 end
2020 return nxt (co .resume (thread ))
@@ -27,12 +27,12 @@ local sync_example = function ()
2727 local x = co .yield (1 )
2828 print (x )
2929 local y , z = co .yield (2 , 3 )
30- print (y )
31- return 4 , 5
30+ print (y , z )
31+ local f = co .yield (4 )
32+ print (f )
3233 end )
3334
34- local w , t = pong (thread )
35- print (w , t )
35+ pong (thread )
3636end
3737
3838
4242
4343
4444local timeout = function (ms , callback )
45- local timer = assert ( uv .new_timer () )
45+ local timer = uv .new_timer ()
4646 uv .timer_start (timer , ms , 0 , function ()
47- assert ( uv .timer_stop (timer ) )
48- assert ( uv .close (timer ) )
47+ uv .timer_stop (timer )
48+ uv .close (timer )
4949 callback ()
5050 end )
5151end
6464local e2 = a .wrap (echo_2 )
6565
6666
67- local async_tasks_1 = a .sync (function ()
68- local x , y = a .wait (e2 (1 , 2 ))
69- print (x , y )
70- return x + y
71- end )
72-
67+ local async_tasks_1 = function ()
68+ return a .sync (function ()
69+ local x , y = a .wait (e2 (1 , 2 ))
70+ print (x , y )
71+ return x + y
72+ end )
73+ end
7374
7475local async_tasks_2 = function (val )
7576 return a .sync (function ()
7677 -- await all
7778 local w , z = a .wait_all {e2 (val , val + 1 ), e2 (val + 2 , val + 3 )}
78- print (unpack (w ), unpack (z ))
79- return 5
79+ print (unpack (w ))
80+ print (unpack (z ))
81+ return 4
8082 end )
8183end
8284
8385
84- local async_example = a .sync (function ()
85- -- composable, await other async thunks
86- local u = a .wait (async_tasks_1 )
87- local v = a .wait (async_tasks_2 (3 ))
88- print (u + v )
89- end )
86+ local async_example = function ()
87+ return a .sync (function ()
88+ -- composable, await other async thunks
89+ local u = a .wait (async_tasks_1 ())
90+ local v = a .wait (async_tasks_2 (3 ))
91+ print (u + v )
92+ end )
93+ end
9094
9195
9296-- #################### ############ ####################
@@ -104,17 +108,21 @@ local vim_command = function ()
104108end
105109
106110
107- local textlock_fail = a .sync (function ()
108- a .wait (e2 (1 , 2 ))
109- vim_command ()
110- end )
111+ local textlock_fail = function ()
112+ return a .sync (function ()
113+ a .wait (e2 (1 , 2 ))
114+ vim_command ()
115+ end )
116+ end
111117
112118
113- local textlock_succ = a .sync (function ()
114- a .wait (e2 (1 , 2 ))
115- a .wait (main_loop )
116- vim_command ()
117- end )
119+ local textlock_succ = function ()
120+ return a .sync (function ()
121+ a .wait (e2 (1 , 2 ))
122+ a .wait (main_loop )
123+ vim_command ()
124+ end )
125+ end
118126
119127
120128return {
0 commit comments