Giter VIP home page Giter VIP logo

gate-executor's Introduction

gate-executor

npm version Build Status Coverage Status Dependency Status Gitter chat

A work queue that can be gated, stopping to wait for sub-queues to complete.

Annotated Source

A work execution queue that provides gating. Work items submitted to the queue are called in order, and execute concurrently. However, if the queue is gated, then a sub-queue is created, and work items added to the sub-queue must complete first.

Gating operates to any depth, allowing you to form a tree-structured queue that must complete breadth-first.

The queue also handles timeouts, so that failing work items do not block processing. Timeouts use a shared setInterval, so are nice and efficient.

Used by the Seneca microservice framework to implement plugin initialisation.

Usage

var GateExecutor = require('gate-executor')

var ge = GateExecutor()

ge.add({
  fn: function first (done) {
    console.log('first')
    done()
  }
})

// create a gate
var subge = ge.gate()

ge.add({
  fn: function second (done) {
    console.log('second')
    done()
  }
})

// this needs to complete before 'second' can run
subge.add({
  fn: function second (done) {
    console.log('third')
    done()
  }
})

ge.start(function () {
  console.log('done')
  done()
})

// prints:
//   first
//   third
//   second
//   done

For detailed information, and API descriptions, see the Annotated Source

Support

If you're using this module, feel free to contact me on twitter if you have any questions! :) @rjrodger

Testing

npm test

gate-executor's People

Contributors

adrieankhisbe avatar geek avatar jakepruitt avatar paolochiodi avatar rjrodger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

gate-executor's Issues

timeout bug

When gate-executor switched from jobs-specific setTimeouts to a generic setInterval a new bug has been introduced.

When the queue is empty the setInterval is cleared, but when a new job is added to the queue it isn't restarted.
This means that jobs added after the first "clear" will never fire a timeout.

Here's a PR with a test that exposes the bug: #15

This is the cause of the error reported in:
senecajs/seneca-amqp-transport#48
senecajs/seneca#517

Consider using fastparallel instead of setImmediate?

I was doing some tracing of an application, and I noted that there was a non-trivial amounts of calls to setImmediate being made in a misbehaving seneca application. It might be a simple but practical micro-optimization.

Also i recall needing to use a setImmediate library to deal with some strange browser compatibility issue in the past, so this might be good for cross-platform support.

https://github.com/mcollina/fastparallel

EventEmitter memory leak detected seems to stem from seneca

    |
api_1             | [ Nodemon ][ Error ] Trace
api_1             |     at GateExecutor.addListener (events.js:252:17)
api_1             |     at GateExecutor.once (events.js:278:8)
api_1             |     at Seneca.api_ready [as ready] (/var/app/current/api/node_modules/seneca/seneca.js:923:30)
api_1             |     at meta.export (/var/app/current/api/node_modules/seneca-web/web.js:661:14)
api_1             |     at Layer.handle [as handle_request] (/var/app/current/api/node_modules/express/lib/router/layer.js:95:5)
api_1             |     at trim_prefix (/var/app/current/api/node_modules/express/lib/router/index.js:312:13)
api_1             |     at /var/app/current/api/node_modules/express/lib/router/index.js:280:7
api_1             |     at Function.process_params (/var/app/current/api/node_modules/express/lib/router/index.js:330:12)
api_1             |     at next (/var/app/current/api/node_modules/express/lib/router/index.js:271:10)
api_1             |     at SessionStrategy.strategy.pass (/var/app/current/api/node_modules/passport/lib/middleware/authenticate.js:325:9)
api_1             |     at SessionStrategy.authenticate (/var/app/current/api/node_modules/passport/lib/strategies/session.js:71:10)
api_1             |     at attempt (/var/app/current/api/node_modules/passport/lib/middleware/authenticate.js:348:16)
api_1             |     at authenticate (/var/app/current/api/node_modules/passport/lib/middleware/authenticate.js:349:7)
api_1             |     at Layer.handle [as handle_request] (/var/app/current/api/node_modules/express/lib/router/layer.js:95:5)
api_1             |     at trim_prefix (/var/app/current/api/node_modules/express/lib/router/index.js:312:13)
api_1             |     at /var/app/current/api/node_modules/express/lib/router/index.js:280:7
api_1             |

I believe this is GateExecutor adding listeners and not removing them

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.