"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/iferr/index.coffee" (7 Feb 2017, 803 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Coffeescript source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    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 
    7 # Like iferr, but also catches errors thrown from `succ` and passes to `fail`
    8 tiferr = (fail, succ) -> iferr fail, (a...) ->
    9   try succ a...
   10   catch err then fail err
   11 
   12 # Delegate to the success function on success, or throw the error otherwise
   13 # ex: Thing.load 123, throwerr (thing) -> ...
   14 throwerr = iferr.bind null, (err) -> throw err
   15 
   16 # Prints errors when one is passed, or does nothing otherwise
   17 # ex: thing.save printerr
   18 printerr = iferr (err) -> console.error err.stack or err
   19 
   20 module.exports = exports = iferr
   21 exports.iferr = iferr
   22 exports.tiferr = tiferr
   23 exports.throwerr = throwerr
   24 exports.printerr = printerr