Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active Jan 5, 2023
Embed
What would you like to do?
extension Publisher where Self.Failure == Never {
func sink(receiveValue: @escaping ((Self.Output) async -> Void)) -> AnyCancellable {
sink { value in
Task {
await receiveValue(value)
}
}
}
}
// Allows writing sink without Task
$imageURL
.compactMap({ $0 })
.sink { [weak self] url in
await self?.processImageURL(url)
}
.store(in: &cancellables)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment