Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats committed Apr 24, 2021
1 parent 85a9cf6 commit c250184
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
14 changes: 8 additions & 6 deletions op_crates/broadcast_channel/01_broadcast_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,14 @@
this[_rid],
);

const event = new MessageEvent("message", {
data: core.deserialize(message),
origin: window.location,
});
event.target = this;
this.dispatchEvent(event);
if (message.length !== 0) {
const event = new MessageEvent("message", {
data: core.deserialize(message),
origin: window.location,
});
event.target = this;
this.dispatchEvent(event);
}
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions op_crates/broadcast_channel/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,21 @@ pub async fn op_broadcast_next_event(

let mut file = RcRef::map(&resource, |r| &r.0).borrow_mut().await;

let size = file.read_u64().await?;
let mut data = Vec::with_capacity(size as usize);
file.read_exact(&mut data).await?;
let size = match file.read_u64().await {
Ok(s) => s,
Err(e) => return match e.kind() {
deno_core::futures::io::ErrorKind::UnexpectedEof => Ok(vec![]),
_ => Err(e.into())
}
};
let mut data = vec![0u8; size as usize];
match file.read_exact(&mut data).await {
Ok(s) => s,
Err(e) => return match e.kind() {
deno_core::futures::io::ErrorKind::UnexpectedEof => Ok(vec![]),
_ => Err(e.into())
}
};

Ok(data)
}
Expand Down

0 comments on commit c250184

Please sign in to comment.