Search in sources :

Example 1 with NullableSyncQueue

use of suite.util.NullableSyncQueue 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)

Example 2 with NullableSyncQueue

use of suite.util.NullableSyncQueue in project suite by stupidsing.

the class FltFunUtil method suck.

/**
 * Sucks data from a sink and produce into a source.
 */
public static FltSource suck(Sink<FltSink> fun) {
    NullableSyncQueue<Float> queue = new NullableSyncQueue<>();
    FltSink 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) Source2(suite.util.FunUtil2.Source2) FltSink(suite.primitive.FltPrimitives.FltSink) Source(suite.util.FunUtil.Source) NullableSyncQueue(suite.util.NullableSyncQueue) Thread_(suite.util.Thread_) Fun(suite.util.FunUtil.Fun) Flt_Obj(suite.primitive.FltPrimitives.Flt_Obj) FltObjPair(suite.primitive.adt.pair.FltObjPair) FltObjSource(suite.primitive.FltPrimitives.FltObjSource) Sink(suite.util.FunUtil.Sink) FltTest(suite.primitive.FltPrimitives.FltTest) Collections(java.util.Collections) FltSource(suite.primitive.FltPrimitives.FltSource) Fail(suite.util.Fail) NullableSyncQueue(suite.util.NullableSyncQueue) FltSink(suite.primitive.FltPrimitives.FltSink)

Example 3 with NullableSyncQueue

use of suite.util.NullableSyncQueue 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);
        }
    };
}
Also used : ChrTest(suite.primitive.ChrPrimitives.ChrTest) Chr_Obj(suite.primitive.ChrPrimitives.Chr_Obj) ChrSink(suite.primitive.ChrPrimitives.ChrSink) Iterator(java.util.Iterator) LogUtil(suite.os.LogUtil) ChrObjPair(suite.primitive.adt.pair.ChrObjPair) Source2(suite.util.FunUtil2.Source2) Source(suite.util.FunUtil.Source) NullableSyncQueue(suite.util.NullableSyncQueue) Thread_(suite.util.Thread_) Fun(suite.util.FunUtil.Fun) ChrObjSource(suite.primitive.ChrPrimitives.ChrObjSource) Sink(suite.util.FunUtil.Sink) Collections(java.util.Collections) Fail(suite.util.Fail) ChrSource(suite.primitive.ChrPrimitives.ChrSource) NullableSyncQueue(suite.util.NullableSyncQueue) ChrSink(suite.primitive.ChrPrimitives.ChrSink)

Example 4 with NullableSyncQueue

use of suite.util.NullableSyncQueue 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);
        }
    };
}
Also used : 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_) IntObjSource(suite.primitive.IntPrimitives.IntObjSource) Fun(suite.util.FunUtil.Fun) IntSource(suite.primitive.IntPrimitives.IntSource) IntTest(suite.primitive.IntPrimitives.IntTest) Int_Obj(suite.primitive.IntPrimitives.Int_Obj) IntSink(suite.primitive.IntPrimitives.IntSink) IntObjPair(suite.primitive.adt.pair.IntObjPair) Sink(suite.util.FunUtil.Sink) Collections(java.util.Collections) Fail(suite.util.Fail) NullableSyncQueue(suite.util.NullableSyncQueue) IntSink(suite.primitive.IntPrimitives.IntSink)

Example 5 with NullableSyncQueue

use of suite.util.NullableSyncQueue 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

Collections (java.util.Collections)5 Iterator (java.util.Iterator)5 LogUtil (suite.os.LogUtil)5 Fail (suite.util.Fail)5 Fun (suite.util.FunUtil.Fun)5 Sink (suite.util.FunUtil.Sink)5 Source (suite.util.FunUtil.Source)5 Source2 (suite.util.FunUtil2.Source2)5 NullableSyncQueue (suite.util.NullableSyncQueue)5 Thread_ (suite.util.Thread_)5 ChrObjSource (suite.primitive.ChrPrimitives.ChrObjSource)1 ChrSink (suite.primitive.ChrPrimitives.ChrSink)1 ChrSource (suite.primitive.ChrPrimitives.ChrSource)1 ChrTest (suite.primitive.ChrPrimitives.ChrTest)1 Chr_Obj (suite.primitive.ChrPrimitives.Chr_Obj)1 DblObjSource (suite.primitive.DblPrimitives.DblObjSource)1 DblSink (suite.primitive.DblPrimitives.DblSink)1 DblSource (suite.primitive.DblPrimitives.DblSource)1 DblTest (suite.primitive.DblPrimitives.DblTest)1 Dbl_Obj (suite.primitive.DblPrimitives.Dbl_Obj)1