Swiftpack.co - Amnell/TaskLoadingAggregate as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Amnell.
Amnell/TaskLoadingAggregate v1.0.0-rc-2
Track your Swift Concurrency Tasks activity in an aggregate with ease.
⭐️ 1
🕓 2 weeks ago
iOS macOS
.package(url: "https://github.com/Amnell/TaskLoadingAggregate.git", from: "v1.0.0-rc-2")

TaskLoadingAggregate

Track your Swift Concurrency Tasks activity in an aggregate with ease.

📄 Description

Swift's Concurrency makes working with asynchronous tasks through async/await a breeze. Hooking up a loading state for one task is just as easy. But what if you have multiple tasks running? Tracking one single loading state in those cases is a bit harder.

Introducing TaskLoadingAggregate 🎉

TaskLoadingAggregate makes this a breeze by creating a loading state aggregate for your tasks. Each tracked task will report their status to the aggregate and as long as a task is loading the aggregate will report isLoading as true.

🎮 Usage

Hooking up a task to a TaskLoadingAggregate is as simple as:

let loadingAggregate = TaskLoadingAggregate()

// First task
Task {
    try await doSomething()
}.track(loadingManager)

// Second task
Task {
    try await doSomethingElse()
}.track(loadingManager)

// You can now bind your UI or whatever to loadingAggregate's @Published isLoading property 🚀

Q: Is this only for Task?

No, you can use a TaskLoadingAggregate however you like, but then it is up to you to increment and decrement the aggregates loading counter:

let loadingAggregate = TaskLoadingAggregate()

// In async function
func doSomething() async {
    loadingAggregate.increment()
    await doSomethingElse()
    loadingAggregate.decrement()
}

// In classic closure
loadingAggregate.increment()
self.doSomething(completion: {
    loadingAggregate.decrement()
})

😋 Who cooked it?

@amnell amnell

⚖️ License

TaskLoadingAggregate is generously distributed under the MIT.

GitHub

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

Release Notes

v1.0.0-rc-2
2 weeks ago

Fixed so that package now works in non pre-release Xcode/swift

What's Changed

New Contributors

Full Changelog: https://github.com/Amnell/TaskLoadingAggregate/compare/v1.0.0-rc-1...v1.0.0-rc-2

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