Skip to content

Instantly share code, notes, and snippets.

@andynovak12
Last active May 7, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andynovak12/62ff7c9a91456fc97375f27de1b5fa38 to your computer and use it in GitHub Desktop.
Save andynovak12/62ff7c9a91456fc97375f27de1b5fa38 to your computer and use it in GitHub Desktop.
Wrapping Asynchronous Functions In ReactiveSwift
// Mock External Library Definitions
func mockAsyncFunction(completion: @escaping (String?, MockError?) -> Void ) {
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
completion("mockAsyncFunction completed successfully", nil)
// uncomment the below line and comment the one above to return an error
// completion(nil, MockError.asyncError)
}
}
enum MockError: Error, LocalizedError {
case asyncError
var errorDescription: String? {
switch self {
case .asyncError:
return "Async had an error"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment