Created
March 1, 2014 12:56
-
-
Save dagda1/9289437 to your computer and use it in GitHub Desktop.
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
export default function async(generatorFunc) { | |
function continuer(verb, arg) { | |
var result; | |
try { | |
result = generator[verb](arg); | |
} catch (err) { | |
return RSVP.Promise.reject(err); | |
} | |
if (result.done) { | |
return result.value; | |
} else { | |
return RSVP.Promise.resolve(result.value).then(callback, errback); | |
} | |
} | |
var generator = generatorFunc(); | |
var callback = continuer.bind(continuer, "next"); | |
var errback = continuer.bind(continuer, "throw"); | |
return callback(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment