Package me.tamkungz.signals
Class Signal<T>
java.lang.Object
me.tamkungz.signals.Signal<T>
- Type Parameters:
T- event payload type
-
Method Summary
Modifier and TypeMethodDescriptionbus()Returns the bus this signal lives on.voidclear()Disconnects every listener of this signal's channel, including ones connected through otherSignalinstances for the same key.Connects a listener.connect(ConnectionGroup group, Consumer<T> listener) Connects a listener and tracks it in a group.Connects a listener that only receives the values a predicate accepts.Connects a filtered listener and tracks it in a group.Returns the payload type of this signal.Returns a new signal that only carries the values a predicate accepts.voidDelivers a value to every listener of this signal, on the calling thread.key()Returns the key of this signal's channel.intCounts the listeners connected to this signal's channel.<R> Signal<R> Returns a new signal that carries every value of this signal converted by a function.Connects a listener that is disconnected after its first value.once(ConnectionGroup group, Consumer<T> listener) Connects a one-shot listener and tracks it in a group.
-
Method Details
-
bus
Returns the bus this signal lives on.- Returns:
- the signal bus
-
key
Returns the key of this signal's channel.- Returns:
- the signal key
-
eventType
Returns the payload type of this signal.- Returns:
- payload class
-
connect
Connects a listener.- Parameters:
listener- listener to call for every value- Returns:
- the connection for this listener
-
connect
Connects a listener and tracks it in a group.- Parameters:
group- group that will disconnect the listenerlistener- listener to call for every value- Returns:
- the connection for this listener
-
connectIf
Connects a listener that only receives the values a predicate accepts.- Parameters:
predicate- decides which values reach the listenerlistener- listener to call for accepted values- Returns:
- the connection for this listener
-
connectIf
Connects a filtered listener and tracks it in a group.- Parameters:
group- group that will disconnect the listenerpredicate- decides which values reach the listenerlistener- listener to call for accepted values- Returns:
- the connection for this listener
-
once
Connects a listener that is disconnected after its first value.- Parameters:
listener- listener to call at most once- Returns:
- the connection for this listener
-
once
Connects a one-shot listener and tracks it in a group.- Parameters:
group- group that will disconnect the listenerlistener- listener to call at most once- Returns:
- the connection for this listener
-
filter
Returns a new signal that only carries the values a predicate accepts.The new signal has its own channel; firing on it does not loop back into this signal. Clearing it also detaches it from this signal.
- Parameters:
predicate- decides which values pass- Returns:
- a derived signal of the same payload type
-
map
Returns a new signal that carries every value of this signal converted by a function.The new signal has its own channel. Clearing it also detaches it from this signal.
- Type Parameters:
R- payload type of the new signal- Parameters:
resultType- payload type of the new signalmapper- converts a value of this signal- Returns:
- a derived signal of the result type
-
fire
Delivers a value to every listener of this signal, on the calling thread.- Parameters:
value- value to deliver
-
listenerCount
public int listenerCount()Counts the listeners connected to this signal's channel.- Returns:
- number of connected listeners
-
clear
public void clear()Disconnects every listener of this signal's channel, including ones connected through otherSignalinstances for the same key. For a signal made byfilter(java.util.function.Predicate<T>)ormap(java.lang.Class<R>, java.util.function.Function<T, R>)it also detaches the signal from its source.
-