Add comment to wasm_ext::Connection (#1165)

This commit is contained in:
Pierre Krieger 2019-06-05 15:49:26 +02:00 committed by GitHub
parent a2550215a0
commit 012c5a948b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -302,6 +302,10 @@ impl Stream for Listen {
} }
/// Active stream of data with a remote. /// 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 { pub struct Connection {
/// The FFI object. /// The FFI object.
inner: SendWrapper<ffi::Connection>, inner: SendWrapper<ffi::Connection>,
@ -419,6 +423,9 @@ impl tokio_io::AsyncRead for Connection {
impl io::Write for Connection { impl io::Write for Connection {
fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> { fn write(&mut self, buf: &[u8]) -> Result<usize, io::Error> {
// 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() { if let Some(mut promise) = self.previous_write_promise.take() {
match promise.poll().map_err(JsErr::from)? { match promise.poll().map_err(JsErr::from)? {
Async::Ready(_) => (), Async::Ready(_) => (),