Last active
May 7, 2018 16:02
-
-
Save andynovak12/62ff7c9a91456fc97375f27de1b5fa38 to your computer and use it in GitHub Desktop.
Wrapping Asynchronous Functions In ReactiveSwift
This file contains 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
// 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