Suspends the current task for at least the given duration in seconds, unless the task is cancelled. If the task is cancelled, throws CancellationError without waiting for the duration.
This function does not block the underlying thread.
Using Task to poll for operation completion (Source)
Applies a processing task (processItem) to each item in parallel. Limits the maximum parallelism of the processing to maxParallelTasks to limit the number of threads created.
All items provided are added to a work queue that is then drained by multiple parallel Tasks.
SwiftConcurrency Library
An open source library with utilities and extensions to support Swift async/await concurrency.
Developed as re-usable components for various projects at XII’s iOS, macOS, and watchOS applications.
Installation
Swift Package Manager
SwiftConcurrencylibrary to add to your projectLicense
See the LICENSE file.
Starting
Tasks with a delay specified in seconds (Source)Creates a task with an optional priority that executes the given operation after an initial delay (in seconds).
This is a shorthand for starting a task and then calling
Task.sleepwith a number of nanoseconds to wait.Task::sleep, but in seconds(Source)Suspends the current task for at least the given duration in seconds, unless the task is cancelled. If the task is cancelled, throws
CancellationErrorwithout waiting for the duration. This function does not block the underlying thread.Using
Taskto poll for operation completion (Source)Performs a polling action at a specific interval, timing out if the action does not return
truewithin the timeout interval.Returns
trueif the polling action succeeds andfalseif the task has timed out or has been cancelled.Processing work items via parallel work queue (Source)
Applies a processing task (
processItem) to each item in parallel. Limits the maximum parallelism of the processing tomaxParallelTasksto limit the number of threads created.All items provided are added to a work queue that is then drained by multiple parallel
Tasks.