co({ task1 = function(this) for i = 1, 5do this.wait("x") print("I am task 1, executing step " .. i) coroutine.yield() end end, task2 = function(this) for i = 1, 10do this.wait("x") print("I am task 2, executing step " .. i) coroutine.yield() end end, task3 = function(this) for i = 1, 10do print("I am task 3, executing step " .. i) if i == 5then this.wait("y") end coroutine.yield() end this.notify("x") end, task4 = function(this) for i = 1, 10do print("I am task 4, executing step " .. i) if i == 9then this.notify("y") end coroutine.yield() end end })
go(function() local segs = { "a", "b", "c" } local i = 1 while i <= #segs do local seg = segs[i] go(function() local j = 0 while j < 5do print(seg, j) time.Sleep(1 * time.Second) j = j + 1 end notify(seg) end) i = i + 1 end for _, seg inipairs(segs) do wait(seg) end print("seg fine") os.exit(1) end) time.Sleep(20 * time.Second) print("time abort")