Skip to content

Instantly share code, notes, and snippets.

@laevandus
Last active October 15, 2023 00:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/7da0c8e2c794b9c4b16f9934cc3df106 to your computer and use it in GitHub Desktop.
Save laevandus/7da0c8e2c794b9c4b16f9934cc3df106 to your computer and use it in GitHub Desktop.
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