5

It would look something like this in Rust; handler would come from JavaScript:

let url = "127.0.0.1:4445"; // JavaScript url
let address = SocketAddr::from_str(url).await.unwrap();
let listener = Listener::bind(&address).await.unwrap();
let mut result = false;
while let Some(stream) = listener.incoming().next().await {
    handler(conn); // JavaScript handler
}

I'm planning to use FFI for the integration in Node.js, but I'm not sure how to use the JavaScript function as a callback from Rust.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Tadej Vengust
  • 1,351
  • 4
  • 18
  • 35
  • 2
    It looks like your question might be answered by the answers of [Is it safe to pass js callback to a ffi function which calls it in another thread?](https://stackoverflow.com/q/38973254/155423). If not, please **[edit]** your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Jun 24 '20 at 14:24
  • Let me check it out if this is what I need(Should take a few days due to vacation) and I will get back to it. Thanks! – Tadej Vengust Jun 24 '20 at 14:40
  • @Shepmaster Yeah this is what I was looking for. You can mark the question as answered. – Tadej Vengust Jun 30 '20 at 07:49

0 Answers0