Swiftpack.co - crane-hiromu/CombineAsyncable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by crane-hiromu.
crane-hiromu/CombineAsyncable 0.3
Bridge from Combine to Concurrency
⭐️ 19
🕓 2 days ago
.package(url: "https://github.com/crane-hiromu/CombineAsyncable.git", from: "0.3")

CombineAsyncable

Description

It bridges from Combine to Concurrency.

A small set of extensions that allow to combine new swift concurrency with Combine.

Here are the details in Japanese.

Operator

.asyncMap

Just<Int>(10)
    .asyncMap { number in
        await doSomething(number)
    }
    .sink { value in
        // handle value
    }
    .store(in: &cancellable)

.asyncMapWithThrows

let subject = PassthroughSubject<(), Never>()

subject
    .asyncMapWithThrows {
        try await APIClient.fetch()
    }
    .sink(receiveCompletion: { result in
        // handle result
    }, receiveValue: { value in
        // handle value
    })
    .store(in: &cancellable)

subject.send(())

.asyncSink

Just<Int>(10)
    .sink { number in
        await doSomething(number)
    }
    .store(in: &cancellable)

.asyncSinkWithThrows

let subject = PassthroughSubject<(), Never>()

subject
    .setFailureType(to: Error.self)
    .asyncSinkWithThrows(receiveCompletion: { result in
        // handling result
    }, receiveValue: {
        let response = try await APIClient.fetch()
        // handling response
    })
    .store(in: &cancellable)

subject.send(())

Swift Package Manager

Add the following dependency to your Package.swift file:

.package(url: "https://github.com/crane-hiromu/CombineAsyncable", "0.3.0"..<"1.0.0")

License

MIT, of course ;-) See the LICENSE file.

GitHub

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

Release Notes

0.3
2 days ago
  • Add asyncSink test code
  • Add asyncSinkWithThrows test code

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