Swiftpack.co - swhitty/Awaiting as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by swhitty.
swhitty/Awaiting 0.3.0
Swift @propertyWrapper that waits asynchronously until the value matches a predicate.
⭐️ 7
🕓 2 weeks ago
iOS macOS
.package(url: "https://github.com/swhitty/Awaiting.git", from: "0.3.0")

Build Codecov Platforms Swift 5.5 License Twitter

Introduction

@Awaiting is a Swift @propertyWrapper that waits asynchronously until the value matches a predicate.

Usage

Any class can declare a property to be @Awaiting as follows:

@Awaiting var isComplete: Bool = false

You then use its projected value to await until some predicate is met;

// Suspends until isComplete == true
_ = try await $isComplete.first(where: { $0 })

Cancellation

CancellationError is thrown if the task is cancelled before the predicate is met.

Optionals

When optionals are wrapped you can wait for the first non nil value:

@Awaiting var name: String?

// Suspends until name != nil
let name = try await $name.some()

Collections

When collections are wrapped you can wait for an element to exist at an index:

@Awaiting var names = [String](https://raw.github.com/swhitty/Awaiting/main/)

// Suspends until names[2] exists
let name = try await $names.value(at: 2)

Or wait for at least n elements to exist:

// Suspends until names.count >= 3
let nonEmpty = try await $names.first(withAtLeast: 3)

Credits

@Awaiting is primarily the work of Simon Whitty.

GitHub

link
Stars: 7
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Related Packages

Release Notes

Swift 5.7
2 weeks ago

minor update to fix concurrency warnings within Swift 5.7

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics