Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coroutine utility #88

Open
MattiaFortunati opened this issue Nov 14, 2012 · 0 comments
Open

Coroutine utility #88

MattiaFortunati opened this issue Nov 14, 2012 · 0 comments

Comments

@MattiaFortunati
Copy link
Collaborator

It would be nice to have a global utility function to perform operations as coroutines, like:

function performAsCoroutine(_function, _param)
local thread = MOAICoroutine.new()
thread:run(_function, _param)
end

so in the _function we can use
coroutine.yield()

I already use this method in my projects , passing the other function to execute at the end of _function as _param.

like:

function performAsCoroutine(_function, _param)
local thread = MOAICoroutine.new()
thread:run(_function, _param)
end

function toPerformAfterCoroutine()
print("coroutine finished")
end

function fCoroutine(nextFunction)
--do something
coroutine.yield()
--other
coroutine.yield()
--other
coroutine.yield()

nextFunction()
end

performAsCoroutine(fCoroutine, toPerformAfterCoroutine)

EDIT:

A sample would be nice, too.
A loading bar sample would be great.
For a loading bar we should have two coroutines:
one for the the loading bar each step moving and yielding,
one for the GUI loading one piece and then yielding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant