Skip to content

Instantly share code, notes, and snippets.

@micHar
Last active February 1, 2021 11:53
Show Gist options
  • Select an option

  • Save micHar/4bbfb67b8dc6fd3d9283ba009832695f to your computer and use it in GitHub Desktop.

Select an option

Save micHar/4bbfb67b8dc6fd3d9283ba009832695f to your computer and use it in GitHub Desktop.
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