Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hydra_Internal_7.swift
@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