Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
public extension Context {
internal func await<T>(_ promise: Promise<T>) throws -> T {
guard self.queue != DispatchQueue.main else {
throw PromiseError.invalidContext
var result: T?
var error: Error?
let semaphore = DispatchSemaphore(value: 0)
promise.then(in: self) { value -> Void in
result = value
}.catch(in: self) { err in
error = err
_ = semaphore.wait(timeout: DispatchTime(uptimeNanoseconds: UINT64_MAX))
guard let promiseValue = result else {
throw error!
return promiseValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.