您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.coffee 803B

123456789101112131415161718192021222324
  1. # Delegates to `succ` on sucecss or to `fail` on error
  2. # ex: Thing.load 123, iferr cb, (thing) -> ...
  3. iferr = (fail, succ) -> (err, a...) ->
  4. if err? then fail err
  5. else succ? a...
  6. # Like iferr, but also catches errors thrown from `succ` and passes to `fail`
  7. tiferr = (fail, succ) -> iferr fail, (a...) ->
  8. try succ a...
  9. catch err then fail err
  10. # Delegate to the success function on success, or throw the error otherwise
  11. # ex: Thing.load 123, throwerr (thing) -> ...
  12. throwerr = iferr.bind null, (err) -> throw err
  13. # Prints errors when one is passed, or does nothing otherwise
  14. # ex: thing.save printerr
  15. printerr = iferr (err) -> console.error err.stack or err
  16. module.exports = exports = iferr
  17. exports.iferr = iferr
  18. exports.tiferr = tiferr
  19. exports.throwerr = throwerr
  20. exports.printerr = printerr