Socket
Socket
Sign inDemoInstall

asca

Package Overview
Dependencies
0
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    asca

Convenient parameter binding for asynchronous functions


Version published
Weekly downloads
10
increased by400%
Maintainers
2
Install size
271 kB
Created
Weekly downloads
 

Readme

Source

Asca

Circle CI Dependency Status Coverage Status

Convenient and readability improving parameter binding for asynchronous JavaScript functions.

  1. load it
asca = require 'asca'
  1. define asynchronous functions using asca

sayHi = asca (name, done) ->
  console.log "Hello #{name}"
  done()
  1. the sayHi method behaves completely normal if called normally, i.e. given all parameters
sayHi 'world', ->   #> "Hello world" & calls the given method when done
  1. 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
  1. This binding allows very readable asynchronous code constructs, for example when using async.js:
# instead of this madness
async.parallel [
  (done) -> sayHi 'world', done
  (done) -> sayHi 'universe', done
]

# or this mess
async.parallel [
  sayHi.bind this, 'world'
  sayHi.bind this, 'universe'
]

# we can now say
async.parallel [
  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.

Keywords

FAQs

Last updated on 27 May 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc