Skip to content

Triggering async function on button click #634

Answered by coderedart
vascoferreira25 asked this question in Q&A
Discussion options

You must be logged in to vote

If you want the application to stop responding until download completes, you can use spawn blocking method of tokio which will download the links but hang until it completes. But a better way would be to send the downloads to tokio which should be running in another thread. Tokio recently updated the guide for this purpose. https://tokio.rs/tokio/topics/bridging

You spawn tokio on another thread, and use the handle or a channel to send tasks like download video to tokio. The main thread and event loop will continue normally because downloads are happening in another thread.

Replies: 3 comments 16 replies

Comment options

You must be logged in to vote
7 replies
@emilk
Comment options

@NiceneNerd
Comment options

@vascoferreira25
Comment options

@NiceneNerd
Comment options

@ChrisRega
Comment options

Answer selected by emilk
Comment options

You must be logged in to vote
8 replies
@lfrancke
Comment options

@ChrisRega
Comment options

@lfrancke
Comment options

@JiveyGuy
Comment options

@coderedart
Comment options

Comment options

You must be logged in to vote
1 reply
@c-git
Comment options

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