Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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