Skip to content

[BUG] TS docs use incorrect syntax to check cancelled signal #1820

Closed
@spiffytech

Description

@spiffytech

Describe the issue
The TS docs for cancellation show object destructuring at the top of the function.

This will not function correctly: JavaScript will resolve the getter at the top of the function into a primitive boolean, which cannot change during the task lifetime. If the task has cancelled === false when it starts, it will remain false for however long the function runs.

To read a dynamic value (i.e., for the getter to actually behave like a getter), it must be read like if (ctx.cancelled).

Additional context
It would also be nice if the docs indicated why both cancelled and abortController are offered.

Having abortController makes sense - we can pass it to fetch etc. But given could check if abortController.signal.aborted, it's not clear when ctx.cancelled` is appropriate to use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions