Asca
Convenient parameter binding for asynchronous functions.
- load asca
asca = require 'asca'
- define asynchronous functions using asca
sayHi = asca (name, done) ->
console.log "Hello #{name}"
done()
- the
sayHi
method behaves completely normal if called normally,
i.e. given an asynchronous callback
sayHi 'world', -> # "Hello world"
- if called without the asynchronous callback,
the
sayHi
method returns a method with all the parameters bound to it.
sayLater = sayHi 'world' # 'sayLater' is a method with the argument
# 'world' bound to it
sayLater -> # "Hello world"
- Use the bound form for very readable asynchronous code constructs,
for example when using async:
# instead of
async.parallel [
(done) -> sayHi 'world', done
(done) -> sayHi 'universe', done
]
# we can now say
async.parallel [
sayHi 'world'
sayHi 'universe'
]
Or other places:
# instead of
setTimeout ((done) -> sayHi 'world', done), 2000
# we can now say
setTimeout sayHi('world'), 2000
There are other libraries like curry
that provide more comprehensive currying and binding,
and might be more appropriate for your intended usage.
This library is focussed around asynchrounous function calling,
for example through error checking specifically for that use case.
It is also extremely lightweight and performant.