Unverified Commit 5d214419 authored by Alexandru Vasile's avatar Alexandru Vasile
Browse files

Maybe accept the subscription


Signed-off-by: default avatarAlexandru Vasile <alexandru.vasile@parity.io>
parent 15f18c01
...@@ -1009,7 +1009,7 @@ impl SubscriptionSink { ...@@ -1009,7 +1009,7 @@ impl SubscriptionSink {
/// Attempt to accept the subscription and respond the subscription method call. /// Attempt to accept the subscription and respond the subscription method call.
/// ///
/// Fails if the connection was closed /// Fails if the connection was closed, or if called multiple times.
pub fn accept(&mut self) -> Result<(), SubscriptionEmptyError> { pub fn accept(&mut self) -> Result<(), SubscriptionEmptyError> {
let id = self.id.take().ok_or(SubscriptionEmptyError)?; let id = self.id.take().ok_or(SubscriptionEmptyError)?;
...@@ -1023,6 +1023,11 @@ impl SubscriptionSink { ...@@ -1023,6 +1023,11 @@ impl SubscriptionSink {
} }
} }
/// Accepts the subscription if previously not accepted.
fn maybe_accept(&mut self) {
let _ = self.accept();
}
/// Send a message back to subscribers. /// Send a message back to subscribers.
/// ///
/// Returns `Ok(true)` if the message could be send /// Returns `Ok(true)` if the message could be send
...@@ -1030,6 +1035,8 @@ impl SubscriptionSink { ...@@ -1030,6 +1035,8 @@ impl SubscriptionSink {
/// Return `Err(err)` if the message could not be serialized. /// Return `Err(err)` if the message could not be serialized.
/// ///
pub fn send<T: Serialize>(&mut self, result: &T) -> Result<bool, serde_json::Error> { pub fn send<T: Serialize>(&mut self, result: &T) -> Result<bool, serde_json::Error> {
self.maybe_accept();
// only possible to trigger when the connection is dropped. // only possible to trigger when the connection is dropped.
if self.is_closed() { if self.is_closed() {
return Ok(false); return Ok(false);
...@@ -1083,6 +1090,8 @@ impl SubscriptionSink { ...@@ -1083,6 +1090,8 @@ impl SubscriptionSink {
T: Serialize, T: Serialize,
E: std::fmt::Display, E: std::fmt::Display,
{ {
self.maybe_accept();
let conn_closed = match self.close_notify.as_ref().map(|cn| cn.handle()) { let conn_closed = match self.close_notify.as_ref().map(|cn| cn.handle()) {
Some(cn) => cn, Some(cn) => cn,
None => { None => {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment