Skip to content

Instantly share code, notes, and snippets.

@malcommac
Created February 4, 2017 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malcommac/89d9befb8cccad16af9ed4e150b557b6 to your computer and use it in GitHub Desktop.
Save malcommac/89d9befb8cccad16af9ed4e150b557b6 to your computer and use it in GitHub Desktop.
Hydra_Internals_3.swift
internal func runBody() {
self.stateQueue.sync {
if state.isPending == false || bodyCalled == true {
return
}
bodyCalled = true
self.context.queue.async {
do {
// body can throws and fail. throwing a promise's body is equal to
// reject it with the same error.
try self.body?( { value in
self.set(state: .resolved(value)) // resolved
}, { err in
self.set(state: .rejected(err)) // rejected
})
} catch let err {
self.set(state: .rejected(err)) // rejected (using throw)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment