- All Superinterfaces:
CloseableChannel
- All Known Implementing Classes:
Channel,CollectSource
A channel source, which can be used to receive values from the channel. See
Channel for more details.-
Method Summary
Modifier and TypeMethodDescriptiondefault <V> Source<V> collectAsView(Function<T, V> f) Creates a view of this source, where the results ofreceive()will be transformed using the given functionf.filterAsView(Predicate<T> p) Creates a view of this source, where the results ofreceive()will be filtered using the given predicatep.default voidInvokes the given function for each received element.receive()Receive a value from the channel.Create a clause which can be used inSelect.select(SelectClause[]).<U> SelectClause<U> receiveClause(Function<T, U> callback) Create a clause which can be used inSelect.select(SelectClause[]).Receive a value from the channel.toList()Accumulates all elements received from the channel into a list.Methods inherited from interface com.softwaremill.jox.CloseableChannel
closedForReceive, closedForSend, done, doneOrClosed, error, errorOrClosed, isClosedForReceive, isClosedForSend
-
Method Details
-
receive
Receive a value from the channel.- Throws:
ChannelClosedException- When the channel is closed.InterruptedException
-
receiveOrClosed
Receive a value from the channel. Doesn't throw exceptions when the channel is closed, but returns a value.- Returns:
- Either a value of type
T, orChannelClosed, when the channel is closed. - Throws:
InterruptedException
-
receiveClause
SelectClause<T> receiveClause()Create a clause which can be used inSelect.select(SelectClause[]). The clause will receive a value from the current channel. -
receiveClause
Create a clause which can be used inSelect.select(SelectClause[]). The clause will receive a value from the current channel, and transform it using the providedcallback. -
collectAsView
Creates a view of this source, where the results ofreceive()will be transformed using the given functionf. Iffreturnsnull, the value will be skipped, and another value will be received.The same logic applies to receive clauses created using this source, which can be used in
Select.select(SelectClause[]).- Parameters:
f- The mapping / filtering function. If the function returnsnull, the value will be skipped.- Returns:
- A source which is a view of this source, with the mapping / filtering function applied.
-
filterAsView
Creates a view of this source, where the results ofreceive()will be filtered using the given predicatep.The same logic applies to receive clauses created using this source, which can be used in
Select.select(SelectClause[]).- Parameters:
p- The predicate to use for filtering.- Returns:
- A source which is a view of this source, with the filtering function applied.
-
forEach
Invokes the given function for each received element. Blocks until the channel is done.- Throws:
ChannelErrorException- When there is an upstream error.InterruptedException
-
toList
Accumulates all elements received from the channel into a list. Blocks until the channel is done.- Throws:
ChannelErrorException- When there is an upstream error.InterruptedException
-