Skip to content

How do I call into libp2p rather than having it call my functions in a loop? #2024

Closed Answered by thomaseizinger
Frederik-Baetens asked this question in Q&A
Discussion options

You must be logged in to vote

Is there a different way to submit that call to tokio, or am I required to create a separate thread which has the same kind of loop as in the tokio chat example, which communicates with the rest of my program through channels?

It doesn't have to be a separate thread. What I've found to work reasonably well is to use the tokio or futures select! macro to poll multiple futures simultaneously. You can see an example of this here:

https://github.com/comit-network/xmr-btc-swap/blob/475aac1387846c8e8351bcd4d3bef4a7e019e806/swap/src/protocol/bob/event_loop.rs#L89-L193

The naming might be bit odd but the way it works is that we have a thing called EventLoop that has ownership of the Swarm and c…

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@Frederik-Baetens
Comment options

@thomaseizinger
Comment options

@Frederik-Baetens
Comment options

@mxinden
Comment options

@thomaseizinger
Comment options

Answer selected by Frederik-Baetens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants