use of suite.primitive.ChrPrimitives.ChrSink in project suite by stupidsing.
the class ChrOutlet method sink.
public void sink(ChrSink sink0) {
ChrSink sink1 = sink0.rethrow();
char c;
while ((c = next()) != ChrFunUtil.EMPTYVALUE) sink1.sink(c);
}
use of suite.primitive.ChrPrimitives.ChrSink in project suite by stupidsing.
the class ChrFunUtil method suck.
/**
* Sucks data from a sink and produce into a source.
*/
public static ChrSource suck(Sink<ChrSink> fun) {
NullableSyncQueue<Character> queue = new NullableSyncQueue<>();
ChrSink enqueue = c -> enqueue(queue, c);
Thread thread = Thread_.startThread(() -> {
try {
fun.sink(enqueue);
} finally {
enqueue(queue, EMPTYVALUE);
}
});
return () -> {
try {
return queue.take();
} catch (InterruptedException ex) {
thread.interrupt();
return Fail.t(ex);
}
};
}
Aggregations