Skip to content

awaitAny silently drops the failure of a losing task #423

Closed

Description

@blacktrs

awaitAny($fast, $slow) returns the first task to finish. Every input task is marked as claimed, so when a losing task later fails, nothing reports it: the exception is dropped. This contradicts the structured-concurrency rule the rest of Async\ follows ("a failure nobody claimed is escalated to the owning scope, never dropped").

<?php
use function Async\{async, spawn, delay, awaitAny};
async(function () {
    $fast = spawn(function () { delay(0.01); return 'fast'; });
    $slow = spawn(function () { delay(0.05); throw new RuntimeException('loser failed'); });
    echo awaitAny($fast, $slow), "\n";
    delay(0.1);
    echo "end\n";
});

Output today: fast, end (the RuntimeException vanishes). Compiled with main + the site branch compiler on macOS arm64.

Decision needed: should awaitAny cancel the losers (like select/Go's errgroup), keep them running but escalate their failures to the scope, or swallow them by design? The current docblock says the outcomes are "not reported". Found while writing the API reference (reference/Async/fn.awaitAny.html).

Activity

  1. added
    bug
    needs-design
    area:runtime
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:runtimebugneeds-design

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions