Почитав http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4024.pdf вспомнились корутины в Unity и кажется они на самом деле fiber’ы, а не couroutine’ы. Например:
public class ExampleClass : MonoBehaviour
{
IEnumerator Coroutine1()
{
yield return new WaitForSeconds(5);
// do something
}
IEnumerator Coroutine2()
{
yield return new WaitForSeconds(5);
// do something
}
IEnumerator Start()
{
// 2 coroutines will be started in the next frame update
// (in the same thread as each MonoBehavior.Update())
// and managed by scheduler (no need to manualy resume
// a coroutine after it yields)
StartCoroutine("Coroutine1");
StartCoroutine("Coroutine2");
}
void Update()
{
// this will be called by the same thread
// which calls Courotine1() or Coroutine2()
// till each yield
}
}
Для сравнения в Lua courutines, а не fibers:
-- doesn't start anything
co = coroutine.create(function ()
for i=1,10 do
print("co", i)
coroutine.yield()
end
end)
-- runs coroutine in the same thread as the caller
-- until first yield
coroutine.resume(co) --> co 1
print(coroutine.status(co)) --> suspended
coroutine.resume(co) --> co 2
coroutine.resume(co) --> co 3
-- more calls
coroutine.resume(co) --> co 10
coroutine.resume(co) -- prints nothing
Я прав?