Last active
February 1, 2021 11:53
-
-
Save micHar/4bbfb67b8dc6fd3d9283ba009832695f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func createPublisher<T>( | |
| wrapper: KoruSuspendWrapper<T> | |
| ) -> AnyPublisher<T?, Error> { | |
| var job: Kotlinx_coroutines_coreJob? = nil | |
| return Deferred { | |
| Future<T?, Error> { promise in | |
| job = wrapper.subscribe( | |
| onSuccess: { item in promise(.success(item)) }, | |
| onThrow: { error in promise(.failure(SharedError(error))) } | |
| ) | |
| }.handleEvents(receiveCancel: { job?.cancel(cause: nil) }) | |
| }.eraseToAnyPublisher() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment