Search in sources :

Example 1 with DblSink

use of suite.primitive.DblPrimitives.DblSink in project suite by stupidsing.

the class DblOutlet method sink.

public void sink(DblSink sink0) {
    DblSink sink1 = sink0.rethrow();
    double c;
    while ((c = next()) != DblFunUtil.EMPTYVALUE) sink1.sink(c);
}
Also used : DblSink(suite.primitive.DblPrimitives.DblSink)

Example 2 with DblSink

use of suite.primitive.DblPrimitives.DblSink in project suite by stupidsing.

the class DblFunUtil method suck.

/**
 * Sucks data from a sink and produce into a source.
 */
public static DblSource suck(Sink<DblSink> fun) {
    NullableSyncQueue<Double> queue = new NullableSyncQueue<>();
    DblSink 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 : DblSink(suite.primitive.DblPrimitives.DblSink) DblSource(suite.primitive.DblPrimitives.DblSource) Dbl_Obj(suite.primitive.DblPrimitives.Dbl_Obj) Iterator(java.util.Iterator) LogUtil(suite.os.LogUtil) Source2(suite.util.FunUtil2.Source2) Source(suite.util.FunUtil.Source) NullableSyncQueue(suite.util.NullableSyncQueue) Thread_(suite.util.Thread_) Fun(suite.util.FunUtil.Fun) DblObjSource(suite.primitive.DblPrimitives.DblObjSource) Sink(suite.util.FunUtil.Sink) Collections(java.util.Collections) Fail(suite.util.Fail) DblTest(suite.primitive.DblPrimitives.DblTest) DblObjPair(suite.primitive.adt.pair.DblObjPair) NullableSyncQueue(suite.util.NullableSyncQueue) DblSink(suite.primitive.DblPrimitives.DblSink)

Aggregations

DblSink (suite.primitive.DblPrimitives.DblSink)2 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 LogUtil (suite.os.LogUtil)1 DblObjSource (suite.primitive.DblPrimitives.DblObjSource)1 DblSource (suite.primitive.DblPrimitives.DblSource)1 DblTest (suite.primitive.DblPrimitives.DblTest)1 Dbl_Obj (suite.primitive.DblPrimitives.Dbl_Obj)1 DblObjPair (suite.primitive.adt.pair.DblObjPair)1 Fail (suite.util.Fail)1 Fun (suite.util.FunUtil.Fun)1 Sink (suite.util.FunUtil.Sink)1 Source (suite.util.FunUtil.Source)1 Source2 (suite.util.FunUtil2.Source2)1 NullableSyncQueue (suite.util.NullableSyncQueue)1 Thread_ (suite.util.Thread_)1