Overview
Upsonic provides flexible mechanisms for task execution, allowing you to run tasks both sequentially and in parallel, with synchronous and asynchronous options. This flexibility enables efficient task processing tailored to your specific requirements, whether you need ordered execution, concurrent processing, or non-blocking operations.Task Execution Methods
Upsonic offers four primary methods for task execution:- Sequential Synchronous - Execute tasks one after another, waiting for each to complete. Ideal for workflows where tasks depend on previous results or when order matters.
- Sequential Asynchronous - Queue tasks for execution without blocking the main thread. Perfect for background processing where you want to continue executing your main program while tasks complete in the background.
- Parallel Synchronous - Execute multiple tasks concurrently, waiting for all to complete. Best for CPU-intensive independent operations where you need maximum throughput but still need all results before proceeding.
- Parallel Asynchronous - Execute multiple tasks concurrently without blocking the main thread. Excellent for responsive applications that need to handle multiple operations simultaneously without freezing the user interface.
Creating Tasks and Agents
Before executing tasks, you need to define your tasks and create an agent to process them:Sequential Task Execution
Synchronous Sequential Execution
Execute tasks one after another, waiting for each task to complete before moving to the next:Asynchronous Sequential Execution
Queue tasks for execution without blocking the main thread:The
print_do_async method returns immediately, allowing your code to continue execution while tasks are processed in the background.Parallel Task Execution
Synchronous Parallel Execution
Execute multiple tasks concurrently and wait for all tasks to complete:Asynchronous Parallel Execution
Execute multiple tasks concurrently without blocking the main thread:Performance Considerations
- Sequential Execution: Best for tasks that must be executed in a specific order or depend on each other’s results
- Parallel Execution: Ideal for independent tasks that can be processed simultaneously
- Synchronous Methods: Provide predictable execution flow but block until completion
- Asynchronous Methods: Improve responsiveness but require careful management of execution flow

