T
- the type of item emitted.public interface WriteStream<T>
Users of a write stream must not call any of the methods of this interface concurrently. That is, write streams are not thread safe.
Modifier and Type | Method and Description |
---|---|
void |
complete()
Signals that the stream has completed and that no more items (or errors) are to come.
|
void |
error(java.lang.Throwable throwable)
Signals a stream error.
|
void |
item(T item)
Emit an item.
|
default <O> WriteStream<O> |
itemMap(Action<? super O> itemMapper)
Deprecated.
since 1.4, use
itemMap(Subscription, Action) |
default <O> WriteStream<O> |
itemMap(Subscription subscription,
Action<? super O> itemMapper)
Creates a new write stream that passes error and complete signals on to this stream, but passes items to the given action.
|
void item(T item)
item
- the item to emitvoid error(java.lang.Throwable throwable)
No other methods should be called on this stream after calling this method. It is not necessary to enforce this on user provided implementations of write streams as this is managed internally.
throwable
- the errorvoid complete()
No other methods should be called on this stream after calling this method. It is not necessary to enforce this on user provided implementations of write streams as this is managed internally.
default <O> WriteStream<O> itemMap(Subscription subscription, Action<? super O> itemMapper)
This effectively creates an upstream write stream that transforms items.
It is often useful when Streams.streamMap(Publisher, StreamMapper)
mapping streams}.
The itemMapper
typically manually calls item(Object)
on this stream, one or more times, when receiving an item.
That is, the action may emit multiple items downstream in a particular invocation.
If the mapper throws an exception, the exception will be emitted via error(Throwable)
and the subscription will be cancelled.
The mapper may call complete()
or error(Throwable)
, but should ensure that it does not call any other methods of this interface after.
O
- the type of item received by the returned write streamsubscription
- the upstream subscriptionitemMapper
- the item mapper@Deprecated default <O> WriteStream<O> itemMap(Action<? super O> itemMapper)
itemMap(Subscription, Action)