Standard Library: Async
Manage concurrent operations
Async.getAll(funcs)
Run each zero-argument function in the list
funcs concurrently. Wait until all functions finish
running and return a list of their results.
fn getA()
sleep(200)
"a"
end
fn getB()
sleep(100)
"b"
end
Async.getAll([getA, getB]) -- Returns ["a", "b"] after 200 ms
Async.getFirst(funcs)
Run the zero-argument functions in the list
funcs concurrently and return the result of the first
one that finishes.
Note: the functions that are still running when the first function finishes should be stopped; however, limitations of JS currently prevent this.
fn getA()
sleep(200)
"a"
end
fn getB()
sleep(100)
"b"
end
Async.getFirst([getA, getB]) -- Returns "b" after 100 ms
Async.sleep(ms)
Pause the current execution branch for ms milliseconds.
sleep(1000) -- Pause for 1 second
Async.yield()
Pause a loop temporarily to allow other concurrently running functions to progress.
Async.yield() -- Pause to allow other functions to run