Skip to content

Commit

Permalink
New flow.until_flows api (#17)
Browse files Browse the repository at this point in the history
Co-authored-by: Mikhail Gudkov <[email protected]>
  • Loading branch information
Vbif and vbif1 authored Jan 22, 2023
1 parent bda384e commit 04d0663
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ludobits/m/flow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,27 @@ function M.play_animation(sprite_url, id)
end)
end

--- Wair until other flow coroutines were finished
-- @param flows one coroutine or array of coroutines
function M.until_flows(flows)
assert(flows)

-- single coroutine
if flows.co then
M.until_true(function()
return coroutine.status(flows.co) == "dead"
end)
return
end

-- several coroutines
for k, v in pairs(flows) do
M.until_true(function()
return coroutine.status(v.co) == "dead"
end)
end
end

function M.ray_cast()
print("flow.ray_cast() is deprecated. Use synchronous ray casts released in Defold 1.2.150 instead!")
end
Expand Down
23 changes: 23 additions & 0 deletions test/test_flow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,28 @@ return function()
wait_seconds(0.25)
assert(flow_finished)
end)

it("should be possible to pause until flows complete", function()
local flow_finished = false
local instance = flow.start(function()
local f1 = flow.parallel(function()
flow.delay(0.3)
end)

local f2 = flow.parallel(function()
flow.delay(0.3)
end)

flow.until_flows(f1)
flow.until_flows({ f1, f2 })
flow_finished = true
end)

wait_seconds(0.2)
assert(not flow_finished)

wait_seconds(0.2)
assert(flow_finished)
end)
end)
end

0 comments on commit 04d0663

Please sign in to comment.