Signal
public class Signal<T> extends Object
Methods
create
public static <T>Signal<T> create()
Signal factory method
ReturnValue
Name | Description |
---|---|
Signal<T>
|
create
public static <T>Signal<T> create(SubscriptionFactory<T> sf)
signal factory method
Parameters
Name | Description |
---|---|
SubscriptionFactory<T> sf
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
empty
public static <T>Signal<T> empty()
empty signal factory
ReturnValue
Name | Description |
---|---|
Signal<T>
|
empty
public static <T>Signal<T> empty(Throwable error)
errored signal factory
Parameters
Name | Description |
---|---|
Throwable error
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
from
public static <T>Signal<T> from(Iterable<T> xs)
create Signal[T] from Iterable[T]
Parameters
Name | Description |
---|---|
Iterable<T> xs
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
from
public static <T>Signal<T> from(T t)
create Signal[T] from a T
Parameters
Name | Description |
---|---|
T t
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
just
public static <T>Signal<T> just(T t)
create Signal[T] from a T (alias to allow Collections)
Parameters
Name | Description |
---|---|
T t
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
merge
public static <T>Signal<T> merge(Signal<? extends T> signal1, Signal<? extends T> signal2)
combine multiple signals of the same type into one
Parameters
Name | Description |
---|---|
Signal<? extends T> signal1
|
|
Signal<? extends T> signal2
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
merge
public static <T>Signal<T> merge(Iterable<Signal<T>> signals)
merge a list of signals of the same type into one
Parameters
Name | Description |
---|---|
Iterable<Signal<T>> signals
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
hasObservers
public boolean hasObservers()
ReturnValue
Name | Description |
---|---|
boolean
|
error
public synchronized void error(Throwable t)
error out this signal
Parameters
Name | Description |
---|---|
Throwable t
|
ReturnValue
Name | Description |
---|---|
void
|
next
public void next(T t)
provide a new value to this signal
Parameters
Name | Description |
---|---|
T t
|
ReturnValue
Name | Description |
---|---|
void
|
hasError
public synchronized boolean hasError()
ReturnValue
Name | Description |
---|---|
boolean
|
isComplete
public synchronized boolean isComplete()
ReturnValue
Name | Description |
---|---|
boolean
|
complete
public synchronized void complete()
mark this signal as being completed
ReturnValue
Name | Description |
---|---|
void
|
map
public <U>Signal<U> map(Fn<? extends T, ? extends U> f)
transform Signal[T] to Signal[U] using T -> U
Parameters
Name | Description |
---|---|
Fn<? extends T, ? extends U> f
|
ReturnValue
Name | Description |
---|---|
Signal<U>
|
flatMap
public <U>Signal<U> flatMap(Fn<? extends T, ? extends Signal<? extends U>> f)
transform Signal[T] to Signal[U] using T -> Signal[U]
Parameters
Name | Description |
---|---|
Fn<? extends T, ? extends Signal<? extends U>> f
|
ReturnValue
Name | Description |
---|---|
Signal<U>
|
switchMap
public <U>Signal<U> switchMap(Fn<? extends T, ? extends Signal<? extends U>> f)
transform Signal[T] to Signal[U] using T -> Signal[U] and complete previous inner observable before emitting.
Parameters
Name | Description |
---|---|
Fn<? extends T, ? extends Signal<? extends U>> f
|
ReturnValue
Name | Description |
---|---|
Signal<U>
|
filter
public Signal<T> filter(Pred<? extends T> f)
remove elements from this Signal that do not match the predicate
Parameters
Name | Description |
---|---|
Pred<? extends T> f
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
takeWhile
public Signal<T> takeWhile(Pred<? extends T> f)
retrieve the beginning of this signal while the predicate is true
Parameters
Name | Description |
---|---|
Pred<? extends T> f
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
take
public Signal<T> take(int count)
retrieve the first count items from this signal
Parameters
Name | Description |
---|---|
int count
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
first
public Signal<T> first()
retrieve the first element of this signal
ReturnValue
Name | Description |
---|---|
Signal<T>
|
drop
public Signal<T> drop(int count)
ignore the first count items from this signal
Parameters
Name | Description |
---|---|
int count
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
dropWhile
public Signal<T> dropWhile(Pred<? extends T> f)
ignore the first items of this signal while the predicate holds
Parameters
Name | Description |
---|---|
Pred<? extends T> f
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
distinct
public Signal<T> distinct()
ReturnValue
Name | Description |
---|---|
Signal<T>
|
a new signal that only returns unique items |
distinctUntilChanged
public Signal<T> distinctUntilChanged()
ReturnValue
Name | Description |
---|---|
Signal<T>
|
a new signal that ignores duplicate consecutive emissions. |
sticky
public Signal<T> sticky()
ReturnValue
Name | Description |
---|---|
Signal<T>
|
a signal that remembers its last value and emits it as the first value on subscribe |
last
public Signal<T> last()
retrieve the last item of this signal
ReturnValue
Name | Description |
---|---|
Signal<T>
|
scan
public <U>Signal<U> scan(U initial, Fn2<? extends U, ? extends T, ? extends U> f)
collate this signal into an accumulator
Parameters
Name | Description |
---|---|
U initial
|
|
Fn2<? extends U, ? extends T, ? extends U> f
|
ReturnValue
Name | Description |
---|---|
Signal<U>
|
shared
public Signal<T> shared()
share any previous operations across subsequent observers
ReturnValue
Name | Description |
---|---|
Signal<T>
|
timeout
public Signal<T> timeout(long timeoms)
timeout this signal after timeoms milliseconds
Parameters
Name | Description |
---|---|
long timeoms
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
timeout
public Signal<T> timeout(long timeoms, String loggingPayload)
timeout this signal after timeoms milliseconds
Parameters
Name | Description |
---|---|
long timeoms
|
|
String loggingPayload
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
recoverWith
public Signal<T> recoverWith(Fn<Throwable, Signal<T>> recoveryF)
Recovers this Signal if it encounters an error by returning a new Signal.
The exception can be inspected to either return a new signal, or another error if it should not be handled.
Parameters
Name | Description |
---|---|
Fn<Throwable, Signal<T>> recoveryF
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
delay
public Signal<T> delay(long delayms)
delay all outputs from this signal by
delayms
Parameters
Name | Description |
---|---|
long delayms
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
countDownTimer
public Signal<T> countDownTimer(long millisInFuture, long countDownInterval)
Schedule a countdown until a time in the future, with regular notifications on intervals along the way.
Parameters
Name | Description |
---|---|
long millisInFuture
|
Millis since epoch when alarm should stop. |
long countDownInterval
|
The interval in millis that the user receives callbacks. |
ReturnValue
Name | Description |
---|---|
Signal<T>
|
tapError
public Signal<T> tapError(Consumer<Throwable> consumer)
Forwards errors to the designated callback without causing subscribe side-effects
Parameters
Name | Description |
---|---|
Consumer<Throwable> consumer
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
forward
public final Subscription forward(Signal<T> signal)
Forwards all events from this Signal to the target signal
Parameters
Name | Description |
---|---|
Signal<T> signal
|
ReturnValue
Name | Description |
---|---|
Subscription
|
tap
public Signal<T> tap(Consumer<T> consumer)
Forwards all next values to the specified consumer for a side-effecting operation.
Parameters
Name | Description |
---|---|
Consumer<T> consumer
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
tapCompletion
public Signal<T> tapCompletion(Runnable consumer)
Forwards completion to the specified consumer for a side-effecting operation.
Parameters
Name | Description |
---|---|
Runnable consumer
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
observeOn
public Signal<T> observeOn(Executor executor)
Executes downstream operators on the providedExecutor.
Parameters
Name | Description |
---|---|
Executor executor
|
ReturnValue
Name | Description |
---|---|
Signal<T>
|
onNext
public final Subscription onNext(Consumer<? extends T> consumer)
Parameters
Name | Description |
---|---|
Consumer<? extends T> consumer
|
ReturnValue
Name | Description |
---|---|
Subscription
|
onComplete
public final Subscription onComplete(Runnable completeHandler)
Parameters
Name | Description |
---|---|
Runnable completeHandler
|
ReturnValue
Name | Description |
---|---|
Subscription
|
onError
public final Subscription onError(Consumer<? extends Throwable> consumer)
Parameters
Name | Description |
---|---|
Consumer<? extends Throwable> consumer
|
ReturnValue
Name | Description |
---|---|
Subscription
|
onTerminate
public final Subscription onTerminate(Consumer<? extends Throwable> consumer)
Subscribes to onError and onComplete of this signal.
consumer
will be called with a null
Throwableif this
has completed successfully, if there is an error, it will be non-null
.
Parameters
Name | Description |
---|---|
Consumer<? extends Throwable> consumer
|
ReturnValue
Name | Description |
---|---|
Subscription
|
observe
public final Subscription observe(Consumer<? extends T> onNext, Consumer<? extends Throwable> onTerminate)
Observes this signal using the specified onNext
and onTerminate
.
Parameters
Name | Description |
---|---|
Consumer<? extends T> onNext
|
will be called for every value on this signal |
Consumer<? extends Throwable> onTerminate
|
will receive a |
ReturnValue
Name | Description |
---|---|
Subscription
|
observe
public final Subscription observe(Observer<? extends T> obs)
observe events on this signal, unsubscribe the Subscription to stop observing
Parameters
Name | Description |
---|---|
Observer<? extends T> obs
|
ReturnValue
Name | Description |
---|---|
Subscription
|
consume
public final Subscription consume()
convenience method to observe all values on this Signal and ignore them, causes side-effects to run.
ReturnValue
Name | Description |
---|---|
Subscription
|
A naive reimplementation of rxjava's Observable<T>
Produces an observable stream of T. All operations are single-threaded, but should otherwise be thread-safe.