Asca
Convenient and readability improving parameter binding for asynchronous JavaScript functions.
- load it
asca = require 'asca'
- define asynchronous functions using asca
sayHi = asca consolelog "Hello " done
- the
sayHi
method behaves completely normal if called normally, i.e. given all parameters
sayHi 'world'-> #> "Hello world" & calls the given method when done
- if called without the last parameter (the asynchronous callback),
the
sayHi
method returns a method with all the given parameters bound to it. This method can be called later by just giving it the callback.
sayWorldLater = sayHi 'world' # 'sayWorldLater' is the sayHi method with # the argument 'world' bound to it sayWorldLater -> #> "Hello world" & calls the given method when done
- This binding allows very readable asynchronous code constructs, for example when using async.js:
# instead of this madness asyncparallel sayHi 'world'done sayHi 'universe'done # or this mess asyncparallel sayHibind this'world' sayHibind this'universe' # we can now say asyncparallel sayHi 'world' sayHi 'universe'
Or in many other places that call a method later
# instead of setTimeout -> sayHi 'world'2000 # we can now say setTimeout sayHi'world'2000
All asynchronous JavaScript methods should behave like this.
There are other libraries like curry that provide more comprehensive currying and binding, and might be more appropriate depending on what you want to do. This library is focussed around delayed asynchrounous function calling, performs error checking specifically for this use case, and does that with high performance while being extremely lightweight.