JSPM

flow-stoplight

1.0.0
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 13780
    • Score
      100M100P100Q137027F
    • License ISC

    Package Exports

    • flow-stoplight

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (flow-stoplight) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    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
      })
    }