From 793cbe56dc368f98bd98381700a9dd9ab46dee67 Mon Sep 17 00:00:00 2001 From: "Hermann D. Schimpf" Date: Mon, 1 Apr 2024 12:00:24 -0400 Subject: [PATCH] Added `Scheduler::removeTask()` method to the README docs --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2eca0a..8876def 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,23 @@ foreach (Scheduler::getTasks() as $task) { } ``` -### Stop all processing immediately +### Remove a pending/running task +You can remove a specific task from the processing queue if you need to. +```php +use HDSSolutions\Console\Parallel\Scheduler; +use HDSSolutions\Console\Parallel\Task; + +foreach (Scheduler::getTasks() as $task) { + // if for some reason you want to remove a task, or just want to free memory when a task finishes + if (someValidation($task) || $task->wasProcessed()) { + // this will remove the task from the processing queue + // IMPORTANT: if the task is already running, it will be stopped + Scheduler::removeTask($task); + } +} +``` + +### Stop processing all tasks immediately If you need to stop all right away, you can call the `Scheduler::stop()` method. This will stop processing all tasks immediately. ```php use HDSSolutions\Console\Parallel\Scheduler;