You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have noticed the API for SubscriptionSink is a bit messy to use if you want to await for stream to be sent via the SubscriptionSink if the connection has already been closed it might leak until the stream/fut "resolves" because the stream itself doesn't know anything of the connection state.
For example given that we have the following impl:
implMyServerTraitfor(){fnsubscribe_to_something(&self,mutsink:SubscriptionSink) -> RpcResult<()>{// assume this stream lives forever and produces items "rarely"...let stream = create_stream();let fut = asyncmove{
stream
.take_while(|sc| future::ready(sink.send(sc).map_or(false, |_| true))).for_each(|_| future::ready(())).await};
tokio::spawn(fut);}}
If connection has already this case the tokio task will live until sink.send fails.
To be on the safe-side you would need to something like:
niklasad1
changed the title
[rpc module]: SubscriptionSink more user-friendly API for sending items from stream or future.
[rpc module]: SubscriptionSink more user-friendly API for sending items from stream.
Jan 12, 2022
We have noticed the API for
SubscriptionSink
is a bit messy to use if you want to await for stream to be sent via theSubscriptionSink
if the connection has already been closed it might leak until the stream/fut "resolves" because the stream itself doesn't know anything of the connection state.For example given that we have the following impl:
If connection has already this case the
tokio task
will live untilsink.send
fails.To be on the safe-side you would need to something like:
The text was updated successfully, but these errors were encountered: