Package kilim

Class Generator<T>

All Implemented Interfaces:
Iterable<T>, Iterator<T>, Fiber.Worker
Direct Known Subclasses:
Fib, Post, Pre, Xorshift.X1

public class Generator<T> extends Continuation implements Iterator<T>, Iterable<T>
A Generator, from the caller's perspective, looks like a normal iterator that produces values. Because a standard iterator's next() method must return every time, the programmer is forced to manage the stack explicitly. The Generator class instead allows one to write a task with an automatically managed stack and couple it to an iterator interface. For example:
 class StringGenerator extends Generator{
   public void execute() throws Pausable {
       while (!done) {
           String s = getNextWord(); // this can pause
           yield(s);  
       }
   }
   private String getNextWord() throws Pausable {
   }
 }
 
 
 
  • Field Details

    • nextVal

      T nextVal
    • done

      boolean done
  • Constructor Details

    • Generator

      public Generator()
  • Method Details