/ConcurrencyPlus

Utilities for working with Swift Concurrency

Primary LanguageSwiftBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

License

ConcurrencyPlus

Utilities for working with Swift Concurrency

Types

TaskQueue

Conceptually similar to a serial DispatchQueue, but can accept async blocks. Unlike with an unstructured Task, this makes it possible to control the ordering of events. A queue of tasks like this introduces the possibility of priority inversions. To help avoid this, you can only set a priority on a per-queue basis, not per-operation.

let queue = TaskQueue()

queue.addOperation {
    await asyncFunction()
    await anotherAsyncFunction()
}

TaskQueue also defines a single global queue, to enable this:

// Without .ordered, the execution order of these tasks is not well-defined.
Task.ordered {
    event1()
}

Task.ordered {
    event2()
}

Task.ordered {
    event3()
}

CancellingContinuation

Just like a CheckedContinuation, but will automatically resume by throwing if it is deallocated without being resumed manually. This is useful for situations where you cannot guarantee that a closure will be called. An example of such a situation is an XPC call.

try await withCancellingContinutation({ continuation in
    funcThatMightNotInvokeItsCallback(completionHandler: { in
        continuation.resume()
    })
})

Suggestions or Feedback

We'd love to hear from you! Get in touch via twitter, an issue, or a pull request.

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.