Created
February 4, 2017 11:08
-
-
Save malcommac/89d9befb8cccad16af9ed4e150b557b6 to your computer and use it in GitHub Desktop.
Hydra_Internals_3.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
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