Package kilim
Class Continuation
java.lang.Object
kilim.Continuation
- All Implemented Interfaces:
Fiber.Worker
- Direct Known Subclasses:
Generator,Pure.PureDemo,Pure.PureMega,Xorshift.X2
a minimal bridge or trampoline between woven and unwoven code
backed by a Fiber
giving the programmer explicit control over the event loop
see Task for a more general and easier to use green thread implementation that automatically handles
the event loop
see Generator for more user friendly wrapper
to use override execute() and call run()
each time run() is called, execute runs until it yields, returns or throws an exception
return value of true means either execute returned or threw an exception (accessible as ex())
with state stored in an internal Fiber field across invocations
to reuse a Continuation, call reset()
Continuation provides no scheduler - it is entirely the responsibility of the calling code to
call run() again once the pausing condition has been satisfied
typically used for state machines and Generators
or to port an existing event loop to kilim
this is a low level facility, see kilim.examples.Xorshift.X2 for an example of direct use
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate Exception(package private) static final Continuation.FakeTaskprivate Fiberprivate static Fiber.MethodRef -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionex()get the stored exceptionvoidexecute()the top level entrypoint for the continuation override this method cannot be called directly - use run() instead use Fiber.yield() to yield control cooperatively and return execution to the caller of run()voidthe woven variant of execute() generated by the weaver overriding this method will cause the weaver to leave it unchanged this is a low level facility (override execute() instead)voidreset()reset the Continuation and corresponding Fiber cannot be called inside execute() subsequent invocations of run() will enter execute() as a normal method, ie at the beginningbooleanrun()perform one iteration of execute() the first invocation begins as a normal method subsequent invocations continue from the most recent yield
-
Field Details
-
runnerInfo
-
fakeTask
-
ex
-
fiber
-
active
private boolean active
-
-
Constructor Details
-
Continuation
public Continuation()
-
-
Method Details
-
ex
get the stored exception- Returns:
- the stored Exception if execute() has thrown one, otherwise null
-
run
perform one iteration of execute() the first invocation begins as a normal method subsequent invocations continue from the most recent yield- Returns:
- true if execute returned or threw an Exception (call ex() to retrieve)
- Throws:
NotPausable
-
execute
the top level entrypoint for the continuation override this method cannot be called directly - use run() instead use Fiber.yield() to yield control cooperatively and return execution to the caller of run()- Specified by:
executein interfaceFiber.Worker- Throws:
PausableException
-
execute
the woven variant of execute() generated by the weaver overriding this method will cause the weaver to leave it unchanged this is a low level facility (override execute() instead)- Specified by:
executein interfaceFiber.Worker- Parameters:
fiber- the stack information automatically provided by run()
-
reset
public void reset()reset the Continuation and corresponding Fiber cannot be called inside execute() subsequent invocations of run() will enter execute() as a normal method, ie at the beginning
-