Skip to content

Instantly share code, notes, and snippets.

@ericlewis
Created September 24, 2020 21:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ericlewis/ce2fe7163f22a03f15279cdea39edfbb to your computer and use it in GitHub Desktop.
Save ericlewis/ce2fe7163f22a03f15279cdea39edfbb 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