Created
September 20, 2014 08:13
-
-
Save fand/c841708956c321a8fe93 to your computer and use it in GitHub Desktop.
Q.Promiseつかう
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
## いろいろなPromiseライブラリを使ってみる | |
## Qだけthrow new Errorが捕まえられなかった | |
# {Promise} = require 'es6-promise' | |
Promise = require('q').Promise | |
# Promise = require 'bluebird' | |
checkOdd = (num) -> | |
return new Promise (resolve) -> | |
if typeof num isnt 'number' | |
throw new Error "#{num} is not number" | |
resolve num % 2 is 1 | |
for i in [0,1,2,3,null,5,"かずどん",7,8] | |
do (i) -> | |
checkOdd i | |
.then (res) -> | |
if res | |
console.log "#{i} is odd" | |
else | |
console.log "#{i} is not odd" | |
.catch (err) -> | |
console.error err |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment