TaskGroup::count

(PHP 8.6+, True Async 1.0)

public TaskGroup::count(): int

Returns the total number of tasks in the group: queued, running, and completed.

TaskGroup implements the Countable interface, so you can use count($group).

Return Value

The total number of tasks (int).

Examples

Example #1 Counting tasks

<?php

use Async\TaskGroup;

spawn(function() {
    $group = new TaskGroup(concurrency: 2);

    $group->spawn(fn() => "a");
    $group->spawn(fn() => "b");
    $group->spawn(fn() => "c");

    echo count($group); // 3

    $group->seal();
    $group->all();

    echo count($group); // 3
});

See Also