Skip to content

Commit

Permalink
Merge pull request #201 from Totodore/feat-ack-stream
Browse files Browse the repository at this point in the history
feat: Better ergonomy for ack responses with custom `AckStream` struct
  • Loading branch information
Totodore authored Jan 2, 2024
2 parents 462f95b + 6032ffb commit 87b8195
Show file tree
Hide file tree
Showing 16 changed files with 1,158 additions and 260 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.10.0
## socketioxide
* Rework for `emit_with_ack` fns. It now returns an `AckStream` that can be used either as a future when expecting one ack or as a stream when expecting multiple acks. When expecting multiple acks the `AckStream` will yield `AckResult`s as well as their corresponding socket `id`.

# 0.9.1
## socketioxide
* Add `SocketIo::get_socket` and `Operators::get_socket` methods to get a socket ref from its id.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ salvo = { version = "0.63.0", features = ["tower-compat"] }
rust_socketio = { version = "0.4.2", features = ["async"] }

[workspace.package]
version = "0.9.1"
version = "0.10.0"
edition = "2021"
rust-version = "1.67.0"
authors = ["Théodore Prévot <"]
Expand Down
14 changes: 14 additions & 0 deletions e2e/socketioxide/socketioxide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ fn on_connect(socket: SocketRef, Data(data): Data<Value>) {
ack.bin(bin).send(data).ok();
},
);

socket.on(
"emit-with-ack",
|s: SocketRef, Data::<Value>(data), Bin(bin)| async move {
let ack = s
.bin(bin)
.emit_with_ack::<Value>("emit-with-ack", data)
.unwrap()
.await
.unwrap();
s.bin(ack.binary).emit("emit-with-ack", ack.data).unwrap();
},
);
}

#[tokio::main]
Expand All @@ -46,6 +59,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (svc, io) = SocketIo::builder()
.ping_interval(Duration::from_millis(300))
.ping_timeout(Duration::from_millis(200))
.ack_timeout(Duration::from_millis(200))
.connect_timeout(Duration::from_millis(1000))
.max_payload(1e6 as u64)
.build_svc();
Expand Down
5 changes: 3 additions & 2 deletions socketioxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ readme = "../README.md"


[dependencies]
engineioxide = { path = "../engineioxide", version = "0.9.1" }
engineioxide = { path = "../engineioxide", version = "0.10" }
futures.workspace = true
tokio = { workspace = true, features = ["rt"] }
tokio = { workspace = true, features = ["rt", "time"] }
serde.workspace = true
serde_json.workspace = true
tower.workspace = true
Expand All @@ -25,6 +25,7 @@ http-body.workspace = true
thiserror.workspace = true
itoa.workspace = true
hyper.workspace = true
pin-project-lite.workspace = true

# Extensions
dashmap = { version = "5.4.0", optional = true }
Expand Down
Loading

0 comments on commit 87b8195

Please sign in to comment.