Skip to content

is the swarm the only way to publish and listen for incoming messages #3369

Closed Answered by elenaf9
revoltez asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @revoltez,
examples/file-sharing.rs might be helpful here. It showcases an alternative architecture for driving and accessing a swarm in a larger application, without a Mutex.
The basic idea there is that the swarm is polled in an event-loop running in a background task, and actions are performed by sending commands via a mpsc channel to this background task. The event-loop performs actions on the swarm accordingly, and returns their result in a one-shot channel once they resolved. This allows to trigger multiple async actions in parallel from multiple threads, since each thread can simply hold one copy of the mpsc::Sender.
Let me know if this helps. 🙂

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@revoltez
Comment options

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