mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-12 19:31:47 +00:00
added async.value for "eventually" collecting the value of a function that can return nothing for a while (eg querying another thread or whatever). not particularly happy with the name, await is probably a loaded term though
This commit is contained in:
parent
24913f05b8
commit
f091c89893
12
async.lua
12
async.lua
@ -191,6 +191,18 @@ function async.wait(time)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--eventually get a result, inline
|
||||||
|
-- repeatedly calls the provided function until it returns something,
|
||||||
|
-- stalling each time it doesn't, returning the result in the end
|
||||||
|
function async.value(f)
|
||||||
|
local r = f()
|
||||||
|
while not r do
|
||||||
|
async.stall()
|
||||||
|
r = f()
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
--make an iterator or search function asynchronous, stalling every n (or 1) iterations
|
--make an iterator or search function asynchronous, stalling every n (or 1) iterations
|
||||||
--can be useful with functional queries as well, if they are done in a coroutine.
|
--can be useful with functional queries as well, if they are done in a coroutine.
|
||||||
function async.wrap_iterator(f, stall, n)
|
function async.wrap_iterator(f, stall, n)
|
||||||
|
Loading…
Reference in New Issue
Block a user