Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hydra_Internals_5.swift
@discardableResult
public func then(in context: Context? = nil, _ body: @escaping ( (Value) throws -> () ) ) -> Promise<Value> {
let ctx = context ?? .main
let nextPromise = Promise<Value>(in: ctx, { resolve, reject in
let onResolve = Observer<Value>.onResolve(ctx, { value in
do {
try body(value)
resolve(value)
} catch let error {
reject(error)
}
})
let onReject = Observer<Value>.onReject(ctx, reject)
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