Created
February 4, 2017 11:14
-
-
Save malcommac/2023f0f4d76f83b4e1fe7bc015788d4b to your computer and use it in GitHub Desktop.
Hydra_Internal_7.swift
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
@discardableResult | |
public func `catch`(in context: Context? = nil, _ body: @escaping ((Error) throws -> (Void))) -> Promise<Void> { | |
let ctx = context ?? .main | |
let nextPromise = Promise<Void>(in: ctx) { resolve, reject in | |
let onResolve = Observer<Value>.onResolve(ctx, { _ in | |
resolve(()) | |
}) | |
let onReject = Observer<Value>.onReject(ctx, { error in | |
do { | |
try body(error) | |
} catch let error { | |
reject(error) | |
} | |
resolve(()) | |
}) | |
self.add(observers: onResolve,onReject) | |
} | |
nextPromise.runBody() | |
self.runBody() | |
return nextPromise | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment