0.0.2 • Published 10 years ago

decor v0.0.2

Weekly downloads
5
License
-
Repository
github
Last release
10 years ago

npm install decor 0.0.2 component install nomilous/decor 0.0.2

decor

assorted function decorators

decor.deferred(fn)

  • Decorates a function to be promisable
  • Injects as a new first argument the promise handler (action)
  • action. resolve(), reject() and notify() as usual from within
  • calling the decorated function returns the promise, availing .then to the caller
  • using q for the promising
{deferred} = require 'decor'

promisingFunction = deferred (action, arg1, argN) -> 
    
    doSomethingAsync arg1, (err, res) -> 

        # action.notify('50% complete')
        return action.reject err if err?
        return action.resolve res


promisingFunction( 'arg1' ).then -> # as usual

#
# or, more fully
#

promisingFunction( 'arg1' ).then(

    (result) -> 
    (error)  -> 
    (notify) -> 

)

decor.Q

  • onward export of q
  • so that it doesn't need to be installed twice by npm

Dev / Test

# sudo npm install ipso-cli -g
npm install
ipso -m
0.0.2

10 years ago

0.0.1

10 years ago

0.0.0

10 years ago