flow-stoplight
A simple flow control mechanism.
Last updated 11 years ago by kumavis .
ISC · Original npm · Tarball · package.json
$ npm install flow-stoplight 
SYNC missed versions from official npm registry.

Stoplight

A simple flow control mechanism.

Has two modes: "go" and "stop".

Starts stopped.

var stoplight = new Stoplight()

stoplight.await(function(){
  // this will called when the stoplight is set to "go"
  // if its already "go", it will be called on the next frame
})

// starts stopped
stoplight.go()

Example

Here is a class that has some async intialization process, but can have its asynchronous method called immediately w/o breaking.


function MyClass() {
  var self = this
  self._stoplight = new Stoplight()
  asyncInitialization(function(){
    self._stoplight.go()
  })
}

MyClass.prototype.asyncMethod = function(cb){
  var self = this
  self._stoplight.await(function(){
    // handle the method here and you can be sure that
    // the async initialization has finished
  })
}

Current Tags

  • 1.0.0                                ...           latest (11 years ago)

1 Versions

  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 3
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE