Skip to content

Commit

Permalink
Merge pull request #190 from Totodore/fix-async-handlers
Browse files Browse the repository at this point in the history
Fix async handlers not run
  • Loading branch information
Totodore authored Dec 5, 2023
2 parents b7674cb + ff78906 commit caa418d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.7.3
## socketioxide
* Fix [#189](https://github.com/Totodore/socketioxide/issues/189). Async message handlers were never called because the returned future was not spawned with `tokio::spawn`.

# 0.7.2
## socketioxide
* The `on_disconnect` callback now takes a `SocketRef` rather than an `Arc<Socket>` to match other handlers. It also avoids that the user clone the socket and create a memory leak.
Expand Down
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ warp = "0.3.6"
salvo = { version = "0.58.5", features = ["tower-compat"] }

[workspace.package]
version = "0.7.2"
version = "0.7.3"
edition = "2021"
rust-version = "1.67.0"
authors = ["Théodore Prévot <"]
Expand Down
3 changes: 2 additions & 1 deletion e2e/socketioxide/socketioxide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ fn on_connect(socket: SocketRef, Data(data): Data<Value>) {
},
);

// keep this handler async to test async message handlers
socket.on(
"message-with-ack",
|Data::<Value>(data), ack: AckSender, Bin(bin)| {
|Data::<Value>(data), ack: AckSender, Bin(bin)| async move {
info!("Received event: {:?} {:?}", data, bin);
ack.bin(bin).send(data).ok();
},
Expand Down
2 changes: 1 addition & 1 deletion socketioxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "../README.md"


[dependencies]
engineioxide = { path = "../engineioxide", version = "0.7.2" }
engineioxide = { path = "../engineioxide", version = "0.7.3" }
futures.workspace = true
tokio = { workspace = true, features = ["rt"] }
serde.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion socketioxide/src/handler/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ macro_rules! impl_async_handler {
},
};

(self.clone())($($ty,)* last);
let fut = (self.clone())($($ty,)* last);
tokio::spawn(fut);
}
}
};
Expand Down

0 comments on commit caa418d

Please sign in to comment.