Created
March 8, 2021 17:57
-
-
Save lammertw/1d9e10889da01f4819b405ce81d1e02e to your computer and use it in GitHub Desktop.
This file contains 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 asPublisher<T>(_ flow: CFlow<T>) -> AnyPublisher<T, Never> { | |
return Deferred<Publishers.HandleEvents<PassthroughSubject<T, Never>>> { | |
let subject = PassthroughSubject<T, Never>() | |
let closable = flow.watch { next in | |
if let next = next { | |
subject.send(next) | |
} | |
} | |
return subject.handleEvents(receiveCancel: { | |
closable.close() | |
}) | |
}.eraseToAnyPublisher() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment