Skip to content

Commit

Permalink
Run flows immediately when started
Browse files Browse the repository at this point in the history
Fixes #14
  • Loading branch information
britzl committed May 31, 2021
1 parent d2312ab commit 0db5c00
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion game.project
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[project]
title = Ludobits
version = 0.7.6
dependencies = https://github.com/britzl/deftest/archive/2.7.0.zip,https://github.com/britzl/defold-input/archive/1.3.0.zip
dependencies#0 = https://github.com/britzl/deftest/archive/2.7.0.zip
dependencies#1 = https://github.com/britzl/defold-input/archive/1.3.0.zip

[bootstrap]
main_collection = /examples/examples.collectionc
Expand Down
19 changes: 9 additions & 10 deletions ludobits/m/flow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,19 @@ end
-- @return The created flow instance
function M.start(fn, options, on_error)
assert(fn, "You must provide a function")
local created_instance = create_or_get(coroutine.create(fn))
created_instance.on_error = on_error

local parallel = options and options.parallel
local co = coroutine.running()
if not co or not instances[co] or (options and options.parallel) then
local created_instance = create_or_get(coroutine.create(fn))
created_instance.on_error = on_error
return created_instance
else
local running_instance = instances[co]
local created_instance = create_or_get(coroutine.create(fn))
created_instance.on_error = on_error
if co and instances[co] and not parallel then
M.until_true(function()
return instances[created_instance.co] == nil
end)
return created_instance
end
else
update_flow(self, 0, created_instance.co)

This comment has been minimized.

Copy link
@GreenArrow18

GreenArrow18 May 31, 2021

self is referenced here, but is not defined elsewhere?

Inside update_flow, self parameter is not used anyway, so it can probably be removed safely?

This comment has been minimized.

Copy link
@britzl

britzl Jun 1, 2021

Author Owner

Good point. I've removed the self reference

end
return created_instance
end


Expand Down
4 changes: 2 additions & 2 deletions test/test_flow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ return function()
assert(instance)
end)

it("should not run the flow immediately when started", function()
it("should run the flow immediately when started", function()
local flow_finished = false
flow.start(function()
flow_finished = true
end)
assert(not flow_finished)
assert(flow_finished)
end)

it("should run the flow on a timer", function()
Expand Down

0 comments on commit 0db5c00

Please sign in to comment.