Difference between revisions of "Coroutine.yield"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> === Description === In order for multiple coroutines to share execution they must stop executing (after performing a sensi...")
 
Line 4: Line 4:
 
In order for multiple coroutines to share execution they must stop executing (after performing a sensible amount of processing) and pass control to another thread. This act of submission is called yielding. Coroutines explicitly call a Lua function coroutine.yield(), which is similar to using return in functions. What differentiates yielding from function returns is that at a later point we can reenter the thread and carry on where we left off. When you exit a function scope using return the scope is destroyed and we cannot reenter it, e.g.,
 
In order for multiple coroutines to share execution they must stop executing (after performing a sensible amount of processing) and pass control to another thread. This act of submission is called yielding. Coroutines explicitly call a Lua function coroutine.yield(), which is similar to using return in functions. What differentiates yielding from function returns is that at a later point we can reenter the thread and carry on where we left off. When you exit a function scope using return the scope is destroyed and we cannot reenter it, e.g.,
 
<source lang="lua">
 
<source lang="lua">
= coroutine.yield(val1...,)
+
coroutine.yield(val1,...)
 
</source>
 
</source>
'''val1:''' (any) value to return from coroutine.resume call '''optional'''<br/>
+
'''val1''': (any) value to return from coroutine.resume call '''optional'''<br/>
'''...:''' (multiple) other optional values that will be returned from coroutine.resume call '''optional'''<br/>
+
'''...''': (multiple) other optional values that will be returned from coroutine.resume call '''optional'''<br/>

Revision as of 10:20, 23 August 2018

Available since: Gideros 2011.6

Description

In order for multiple coroutines to share execution they must stop executing (after performing a sensible amount of processing) and pass control to another thread. This act of submission is called yielding. Coroutines explicitly call a Lua function coroutine.yield(), which is similar to using return in functions. What differentiates yielding from function returns is that at a later point we can reenter the thread and carry on where we left off. When you exit a function scope using return the scope is destroyed and we cannot reenter it, e.g.,

 coroutine.yield(val1,...)

val1: (any) value to return from coroutine.resume call optional
...: (multiple) other optional values that will be returned from coroutine.resume call optional