Comments (4)
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.
from rust-socketio.
Fair point! Didn't think about this in the implementation. I am very happy to accept a PR for this!
from rust-socketio.
@doraeric In your example, you are missing move
for tx
. Once you do that it should work.
{
let (tx, rx) = channel::<String>();
let tx_clone = tx.clone();
let callback = move |payload: Payload, socket: RawClient| {
tx_clone.send("...");
};
let callback2 = move |payload: Payload, socket: RawClient| {
tx.send("...");
};
let socket = ClientBuilder::new(url)
.on("evt1", callback)
.on("evt2", callback2)
.connect()
.expect("Connection failed");
}
from rust-socketio.
@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:
expected a closure that implements the `FnMut` trait, but this closure only implements `FnOnce`
this closure implements `FnOnce`, not `FnMut`
from rust-socketio.
Related Issues (20)
- Server support HOT 2
- error add overflow when reconnect HOT 5
- Rust socket io server implementation? HOT 2
- EngineIO does not timeout on missing pings
- Add feature to use rustls instead of native-tls HOT 1
- Buffer is not supported when it's a field in an JS object? HOT 2
- Manual disconnect doesn't block reconnecting HOT 1
- Add support for WebTransport HOT 2
- add macro to simplyfy async callback define HOT 4
- Allow async connections to update auth when reconnecting HOT 4
- [feature request] custom-parser support HOT 5
- Unable to cross-compile for android HOT 1
- Multiple payload still broke HOT 2
- when using binary buf data with emit_with_ack function callback is not executed
- Is it possible to add `.on()` event callback after connect like in JavaScript? HOT 1
- Unable to use shared variable in async callback HOT 4
- Binary Data event names incorrectly handled HOT 1
- Introduce Custom shared data structure
- [bug] unable to connect to an http based socketio server HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust-socketio.