Package kilim
Class Generator<T>
- java.lang.Object
-
- kilim.Continuation
-
- kilim.Generator<T>
-
- All Implemented Interfaces:
java.lang.Iterable<T>,java.util.Iterator<T>,Fiber.Worker
- Direct Known Subclasses:
Fib,Post,Pre,Xorshift.X1
public class Generator<T> extends Continuation implements java.util.Iterator<T>, java.lang.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 { } }
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class kilim.Continuation
Continuation.FakeTask
-
-
Field Summary
Fields Modifier and Type Field Description (package private) booleandone(package private) TnextVal-
Fields inherited from class kilim.Continuation
fakeTask
-
-
Constructor Summary
Constructors Constructor Description Generator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanhasNext()java.util.Iterator<T>iterator()Tnext()voidremove()voidyield(T val)
-
-
-
Field Detail
-
nextVal
T nextVal
-
done
boolean done
-
-