TaskChain
TaskChain
is a Rust crate that ensures tasks are executed sequentially based on signals, preventing parallel execution. It manages tasks using a signaling mechanism, allowing tasks to either proceed based on an "ANY" task signal or a specified task signal. This crate is useful in scenarios where precise control over task execution order is needed.
Features
- Sequential Task Execution: Tasks proceed one at a time based on signals.
- Two Modes of Task Execution:
- ANY Mode: Multiple tasks can wait, but only one task will be triggered to proceed.
- Specified Mode: Only a specific task is allowed to proceed when triggered.
- Signal-Based Control: Using
Signal
andKinds
enums to control the task flow. - Timeout Support: Tasks can optionally wait for a specified duration before proceeding.
- Automatic Signaling: If a
TaskChain
instance is dropped, the next signal is automatically triggered, ensuring no deadlocks.
Usage
Example: Sequential Task Execution
The following example demonstrates how to use TaskChain
for managing sequential tasks:
use ;
use thread;
use Duration;
use ;
// Create a shared CondvarPair and an atomic counter.
let cvp = new;
let count = new;
// Start the thread scope to manage multiple threads.
scope;
// Ensure all threads completed and incremented the counter.
assert_eq!;
Features Overview
• CondvarPair: A structure managing the synchronization of tasks via signals. • Kinds Enum: Specifies the kind of task expected to proceed (ANY or SPECIFIED). • Signal Enum: Controls the signaling in the taskchain (INACTIVE or TRIGGER with a Kinds value). • TaskChain: The main structure managing task execution flow.
Timeout Support
Tasks can wait for a specified duration before timing out. If a timeout occurs, the task will stop waiting and proceed without receiving the expected signal:
let mut pl = new;
if pl.wait else
License
Licensed under the Apache License, Version 2.0 (the “License”). You may not use this file except in compliance with the License. You may obtain a copy of the License at Apache License 2.0.