Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
## いろいろな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"
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