From 012c5a948bc7382b19680bf33dc8c815e87b19b8 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Wed, 5 Jun 2019 15:49:26 +0200 Subject: [PATCH] Add comment to wasm_ext::Connection (#1165) --- transports/wasm-ext/src/lib.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/transports/wasm-ext/src/lib.rs b/transports/wasm-ext/src/lib.rs index ec4d5ddc..75ade4fe 100644 --- a/transports/wasm-ext/src/lib.rs +++ b/transports/wasm-ext/src/lib.rs @@ -302,6 +302,10 @@ impl Stream for Listen { } /// Active stream of data with a remote. +/// +/// It is guaranteed that each call to `io::Write::write` on this object maps to exactly one call +/// to `write` on the FFI. In other words, no internal buffering happens for writes, and data can't +/// be split. pub struct Connection { /// The FFI object. inner: SendWrapper, @@ -419,6 +423,9 @@ impl tokio_io::AsyncRead for Connection { impl io::Write for Connection { fn write(&mut self, buf: &[u8]) -> Result { + // Note: as explained in the doc-comments of `Connection`, each call to this function must + // map to exactly one call to `self.inner.write()`. + if let Some(mut promise) = self.previous_write_promise.take() { match promise.poll().map_err(JsErr::from)? { Async::Ready(_) => (),