/** * @return Signal backed by a queue */ public static <T> Signal<T> queueBackedSignal() { return new Signal<T>( new Queue<T>( new LinkedBlockingQueue<T>(), null), new Queue<T>( new LinkedBlockingQueue<T>(), null)); }
/** * @return Signal backed by a topic */ public static <T> Signal<T> topicBackedSignal() { return new Signal( new Topic<>(), new Topic<>()); }
public ReactiveSeq<T> changes(){ com.oath.cyclops.async.adapters.Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Spliterator<T> copy = copy(); Continuation[] contRef ={null}; Signal<T> signal = new Signal<T>(null, queue); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(()->{ if(wip.compareAndSet(false,true)) { if(!copy.tryAdvance(signal::set)){ signal.close(); return Continuation.empty(); } wip.set(false); } return contRef[0]; }); contRef[0]= cont; queue.addContinuation(cont); return signal.getDiscrete().stream(); }
/** * @return Signal backed by a queue */ public static <T> Signal<T> queueBackedSignal() { return new Signal<T>( new Queue<T>( new LinkedBlockingQueue<T>(), null), new Queue<T>( new LinkedBlockingQueue<T>(), null)); }
/** * @return Signal backed by a topic */ public static <T> Signal<T> topicBackedSignal() { return new Signal( new Topic<>(), new Topic<>()); }
public ReactiveSeq<T> changes(){ com.oath.cyclops.async.adapters.Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Spliterator<T> copy = copy(); Continuation[] contRef ={null}; Signal<T> signal = new Signal<T>(null, queue); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(()->{ if(wip.compareAndSet(false,true)) { if(!copy.tryAdvance(signal::set)){ signal.close(); return Continuation.empty(); } wip.set(false); } return contRef[0]; }); contRef[0]= cont; queue.addContinuation(cont); return signal.getDiscrete().stream(); }