use of suite.util.Thread_ in project suite by stupidsing.
the class IntFunUtil method suck.
/**
* Sucks data from a sink and produce into a source.
*/
public static IntSource suck(Sink<IntSink> fun) {
NullableSyncQueue<Integer> queue = new NullableSyncQueue<>();
IntSink 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);
}
};
}
use of suite.util.Thread_ in project suite by stupidsing.
the class LngFunUtil method suck.
/**
* Sucks data from a sink and produce into a source.
*/
public static LngSource suck(Sink<LngSink> fun) {
NullableSyncQueue<Long> queue = new NullableSyncQueue<>();
LngSink 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