Package kilim

Class Continuation

java.lang.Object
kilim.Continuation
All Implemented Interfaces:
Fiber.Worker
Direct Known Subclasses:
Generator, Pure.PureDemo, Pure.PureMega, Xorshift.X2

public abstract class Continuation extends Object implements Fiber.Worker
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
    Modifier and Type
    Class
    Description
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
     
    private Exception
     
    (package private) static final Continuation.FakeTask
     
    private Fiber
     
    private static Fiber.MethodRef
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    ex()
    get the stored exception
    void
    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()
    void
    execute(Fiber fiber)
    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)
    void
    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
    boolean
    run()
    perform one iteration of execute() the first invocation begins as a normal method subsequent invocations continue from the most recent yield

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Continuation

      public Continuation()
  • Method Details

    • ex

      public Exception ex()
      get the stored exception
      Returns:
      the stored Exception if execute() has thrown one, otherwise null
    • run

      public boolean run() throws NotPausable
      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

      public void execute() throws Pausable, Exception
      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:
      execute in interface Fiber.Worker
      Throws:
      Pausable
      Exception
    • execute

      public void execute(Fiber fiber)
      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:
      execute in interface Fiber.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