Package kilim

Class Continuation

  • All Implemented Interfaces:
    Fiber.Worker
    Direct Known Subclasses:
    Generator, Pure.PureDemo, Pure.PureMega, Xorshift.X2

    public abstract class Continuation
    extends java.lang.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  Continuation.FakeTask  
    • Constructor Summary

      Constructors 
      Constructor Description
      Continuation()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Exception ex()
      get the stored exception
      void 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()
      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()
      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
    • Constructor Detail

      • Continuation

        public Continuation()
    • Method Detail

      • ex

        public java.lang.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,
                            java.lang.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
        java.lang.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