Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sergeytimoshin/beec803a0139624fa9399d003db353d0 to your computer and use it in GitHub Desktop.
Save sergeytimoshin/beec803a0139624fa9399d003db353d0 to your computer and use it in GitHub Desktop.
import LinkPresentation
import Combine
extension LPMetadataProvider {
func startFetchingMetadataPublisher(for url: URL) -> AnyPublisher<LPLinkMetadata?, Error> {
Future<LPLinkMetadata?, Error> { completion in
self.startFetchingMetadata(for: url) { meta, error in
guard let error = error else {
return completion(.success(meta))
}
completion(.failure(error))
}
}
.handleEvents(receiveCancel: {
self.cancel()
})
.eraseToAnyPublisher()
}
}
let provider = LPMetadataProvider()
let cancellable: AnyCancellable = provider.startFetchingMetadataPublisher(for: URL(string: "https://apple.com")!)
.receive(on: RunLoop.main)
.sink(receiveCompletion: { completion in }) {
print($0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment