Skip to content

Cancel all operations #6

@groue

Description

@groue

Can we add a cancelAllOperations() method?

Currently, this conflicts with the fact that the perform methods prefer running in the current task:

// AsyncQueues 0.3.0

let queue = AsyncQueue()
await queue.perform {
  // In the same task as the caller
}

For cancelAllOperations() to work, we'd need to run those operations in a distinct task:

// With hypothetic support for cancelling all operations

let queue = AsyncQueue()
await queue.perform {
  // Must be in a distinct task than the caller
  // so that we can cancel this operation.
}

This would be a breaking change:

let queue = AsyncQueue()

await queue.perform {
  // Would not cancel the same task
  withUnsafeCurrentTask { currentTask in
    currentTask?.cancel()
  }
}

cc @mattmassicotte - in case you'd have hindsights about the differences between running in the current task vs. a new top-level Task created from the current task, and why one could prefer one or the other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions