Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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