Task Forge
A flexible and asynchronous task forge for concurrent task execution in Rust. Task Forge
allows you to spawn tasks, send messages, and handle task outputs efficiently using Tokio channels.
Table of Contents
Features
- Spawn and manage multiple asynchronous tasks.
- Send messages to tasks and receive their outputs.
- Track task states (
Running
,Closed
). - Automatically notify when tasks complete or when the forge is cleaned.
- Flexible task creation with support for generic task arguments.
- Customizable error handling using different error handlers.
- Wait for all tasks to end with an optional timeout.
Installation
To add task_forge
to your project, include the following in your Cargo.toml
:
[]
= "0.1.1" # Replace with the latest version
= { = "1", = ["full"] }
Examples
Basic Example
Below is a simple example using the TaskForge
to create and run a basic task:
use ;
;
async
Waiting for Task Creation
You can ensure that a task is fully created before sending a message using wait_for_task_creation
:
let task_id = 42;
spawn;
Or you can use wait_and_send
which does the same work:
let task_id = 42;
spawn;
Handling Concurrent Tasks
You can spawn and manage multiple tasks concurrently:
;
for i in 0..5
Error Handling
task_forge
provides several built-in error handling mechanisms:
panic_error_handler
: Panics when an error occurslog_error_handler
: Logs the errorsignore_error_handler
: Silently ignores all errors
To use a custom error handler, pass the appropriate receiver when creating the forge:
use log_error_handler;
let = new;
log_error_handler;
You can also create your own error handler by using the error receiver.
Licence
This project is licensed under the MIT Licence. Let me know if you’d like any changes or additions!