Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matias-gabriel/rust_tokio_signals_practices
Small study with tokio and unix signals
https://github.com/matias-gabriel/rust_tokio_signals_practices
Last synced: 3 months ago
JSON representation
Small study with tokio and unix signals
- Host: GitHub
- URL: https://github.com/matias-gabriel/rust_tokio_signals_practices
- Owner: matias-gabriel
- Created: 2023-02-08T21:30:45.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-02-09T21:44:59.000Z (almost 2 years ago)
- Last Synced: 2024-06-30T13:40:13.810Z (5 months ago)
- Language: Rust
- Homepage:
- Size: 3.91 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# Background Tasks in Rust with Tokio
This code demonstrates how to run multiple background tasks in Rust using the Tokio library. The code uses async/await syntax and Tokio's `tokio::spawn` function to run tasks concurrently.
A vector of durations, `background_task_times`, is passed to the `run_background_tasks` function, which then creates and spawns a new task for each duration. Each task runs for its specified duration and increments a shared value. The shared value is stored in an `Arc>`, which allows for safe, concurrent access to the value.
The main function listens for a `SIGTERM` signal using the `tokio::signal` library, and if it receives the signal, it waits for all the background tasks to complete before terminating the process.