Search in sources :

Example 31 with Fun

use of suite.util.FunUtil.Fun 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);
        }
    };
}
Also used : Iterator(java.util.Iterator) LogUtil(suite.os.LogUtil) LngSource(suite.primitive.LngPrimitives.LngSource) Source2(suite.util.FunUtil2.Source2) Lng_Obj(suite.primitive.LngPrimitives.Lng_Obj) Source(suite.util.FunUtil.Source) NullableSyncQueue(suite.util.NullableSyncQueue) Thread_(suite.util.Thread_) LngObjSource(suite.primitive.LngPrimitives.LngObjSource) Fun(suite.util.FunUtil.Fun) Sink(suite.util.FunUtil.Sink) LngObjPair(suite.primitive.adt.pair.LngObjPair) LngTest(suite.primitive.LngPrimitives.LngTest) Collections(java.util.Collections) Fail(suite.util.Fail) LngSink(suite.primitive.LngPrimitives.LngSink) NullableSyncQueue(suite.util.NullableSyncQueue) LngSink(suite.primitive.LngPrimitives.LngSink)

Aggregations

Fun (suite.util.FunUtil.Fun)31 Node (suite.node.Node)18 Fail (suite.util.Fail)13 List (java.util.List)12 TermOp (suite.node.io.TermOp)12 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 Suite (suite.Suite)11 Tree (suite.node.Tree)11 Source (suite.util.FunUtil.Source)11 Atom (suite.node.Atom)10 Reference (suite.node.Reference)10 Pair (suite.adt.pair.Pair)9 Int (suite.node.Int)9 Read (suite.streamlet.Read)9 Iterate (suite.util.FunUtil.Iterate)8 To (suite.util.To)7 Collections (java.util.Collections)6 Entry (java.util.Map.Entry)6 LogUtil (suite.os.LogUtil)6