Created
September 24, 2020 21:59
-
-
Save ericlewis/ce2fe7163f22a03f15279cdea39edfbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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