Skip to content

Latest commit

 

History

History
22 lines (16 loc) · 633 Bytes

README.md

File metadata and controls

22 lines (16 loc) · 633 Bytes

asa

Simple module that takes two functions, is_ready and doit, waiting until is_ready returns true to call doit. Useful when waiting for asynchronous entities to become available, for example if writing a command line script that accesses a database.

asa = require 'asa'

# is_ready: a function that determines readiness.
ready = false
is_ready = -> return ready?

# doit: a function that does something.
doit = -> console.log 'it has been done'

# As soon as it's ready, do it.
asa is_ready, doit

# After 1.5 seconds, is_ready will return true and doit will be called.
setTimeout ->
  ready = true
, 1500