|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.sys.Coroutine
A Coroutine is a non-preemptive implementation of a multi-threading. Only one Coroutine will ever by running at a time and control is only passed to other Coroutines when Coroutine.sleep(int millis) is called.
Ewe is single-threaded and only one callback or coroutine thread is ever running at one time (although the Vm itself may have multiple threads servicing these various functions). However callback threads are NOT Coroutine threads.
Avoid creating Coroutines directly - instead use the ewe.sys.mThread object instead. This object has a very similar API to a standard Java Thread and uses a Coroutine as its "engine" when started.
You have to explicitly create Coroutine threads yourself by calling the constructor and passing it a Runnable object.
| Field Summary | |
protected int |
context
|
protected Runnable |
runnable
|
boolean |
showExceptionTrace
If this is true then any uncaught throwable/exception that causes the Coroutine to exit will be displayed. |
| Constructor Summary | |
Coroutine(Object target,
Method runMethod,
Object targetData)
Deprecated. use an mThread object instead. |
|
Coroutine(Object target,
String methodName,
Object targetData)
Deprecated. use an mThread object instead. |
|
Coroutine(Runnable r)
Deprecated. use an mThread object instead. |
|
Coroutine(Runnable r,
int stackSize)
Deprecated. - use an mThread object instead. |
|
| Method Summary | |
protected void |
_nativeCreate(int stackSize)
|
static int |
count()
This returns a count of all running Coroutines. |
static Coroutine |
getCurrent()
Find the Coroutine which is running the current thread. |
void |
interrupt()
Interrupts the Coroutine if it was in a sleep() or a join(). |
boolean |
isRunning()
Returns whether the Coroutine is still running. |
static int |
join(Coroutine other,
int millis)
Tells the current Coroutine thread to sleep until the other Coroutine thread has exited. |
static int |
nap(int iterations,
int time)
This calls sleep(time) every "iterations" calls of this method. |
void |
run()
This will actually not get called! |
static int |
sleep(int howLong)
Puts the current Coroutine thread to sleep, thereby allowing other coroutines as well as message/timer/callback threads to run. |
void |
wakeup()
Deprecated. - use interrupt() instead, interrupt() will interrupt join() calls. |
static void |
yield()
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
protected int context
protected Runnable runnable
public boolean showExceptionTrace
| Constructor Detail |
public Coroutine(Runnable r,
int stackSize)
public Coroutine(Runnable r)
public Coroutine(Object target,
Method runMethod,
Object targetData)
public Coroutine(Object target,
String methodName,
Object targetData)
| Method Detail |
public final void run()
run in interface Runnableprotected final void _nativeCreate(int stackSize)
public final boolean isRunning()
public static final Coroutine getCurrent()
public static final void yield()
public static final int sleep(int howLong)
howLong - - The length of time in milliseconds to sleep. If howLong == -1 it will sleep
until interrupt() is envoked on it.
public static final int join(Coroutine other,
int millis)
other - The other Coroutine to wait for.
public final void wakeup()
public final void interrupt()
public static final int count()
public static final int nap(int iterations,
int time)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||