-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Event handler lifetime shouldn't be static #363
Comments
I just found that crossbeam_channel works for me since the sender can be cloned. But I still think the handler should have shorter lifetime. |
Fair point! Didn't think about this in the implementation. I am very happy to accept a PR for this! |
@doraeric In your example, you are missing
|
@vishalcjha How to transform your example code to use async? I had a lot of trouble with this. For example #[tokio::main]
async fn main() {
let (tx, rx) = channel::<String>();
let tx_clone = tx.clone();
let callback = |payload: Payload, socket: Client| {
async move {
tx_clone.send("...".to_string());
}.boxed()
};
let callback2 = |payload: Payload, socket: Client| {
async move {
tx.send("...".to_string());
}.boxed()
};
let socket = ClientBuilder::new("")
.on("evt1", callback)
.on("evt2", callback2)
.connect()
.await
.expect("Connection failed");
} Always gives error:
|
rust-socketio/socketio/src/client/builder.rs
Lines 169 to 172 in 095db3a
Currently, when building client with event handler, the lifetime of the event handler is required to be static, but I think it should be as long as the client instance.
I want to pass some objects, queue for example, to handlers without transferring ownership. It seems impossible at the moment.
This is the code that I want to use
The text was updated successfully, but these errors were encountered: