-
Hi, I am totally new in async programming and need some starting point. I would like to write a server which polls every 60 seconds (or so) an external REST API to fetch some data. Then process this data and again calls an external REST API with some commands. While doing so I would like to be able to communicate with this server. For example I would like so signal that the server should shutdown. In order to shutdown I would like to cancel every outgoing REST request, update some file and exit the process. I am making the rest calls using reqwest. My very first approach was to:
While this kinda works I cannot signal the server anything. I was trying to use tokio::signal::ctrl_c like so:
But this approach does not work. I learned that async in Rust is lazy therefore the function I am thinking that the Stream API could work, like:
Ideally this stream would react to Tcp-Events and signals (e.g. ctrlc). But I am clueless how to implement such a stream. I am thankful for every hint. Kind regards |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
To kill a currently running task, check out this answer. |
Beta Was this translation helpful? Give feedback.
To kill a currently running task, check out this answer.