Skip to content

Commit

Permalink
fix(ext/websocket): make try_send ops infallible (#16454)
Browse files Browse the repository at this point in the history
Fixes #16450
  • Loading branch information
littledivy authored Oct 31, 2022
1 parent 80ed54a commit d760141
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions ext/websocket/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,19 +505,25 @@ pub fn op_ws_try_send_string(
state: &mut OpState,
rid: ResourceId,
text: String,
) -> Result<bool, AnyError> {
let resource = state.resource_table.get::<WsStreamResource>(rid)?;
resource.try_send(Message::Text(text))
) -> bool {
let resource = match state.resource_table.get::<WsStreamResource>(rid) {
Ok(resource) => resource,
Err(_) => return false,
};
resource.try_send(Message::Text(text)).is_ok()
}

#[op(fast)]
pub fn op_ws_try_send_binary(
state: &mut OpState,
rid: u32,
value: &[u8],
) -> Result<bool, AnyError> {
let resource = state.resource_table.get::<WsStreamResource>(rid)?;
resource.try_send(Message::Binary(value.to_vec()))
) -> bool {
let resource = match state.resource_table.get::<WsStreamResource>(rid) {
Ok(resource) => resource,
Err(_) => return false,
};
resource.try_send(Message::Binary(value.to_vec())).is_ok()
}

#[op(deferred)]
Expand Down

0 comments on commit d760141

Please sign in to comment.