Skip to content

Instantly share code, notes, and snippets.

@fand
Created September 20, 2014 08:13
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 fand/c841708956c321a8fe93 to your computer and use it in GitHub Desktop.
Save fand/c841708956c321a8fe93 to your computer and use it in GitHub Desktop.
Q.Promiseつかう
## いろいろな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