Giter VIP home page Giter VIP logo

gate-executor's Introduction

gate-executor

Execute functions that return via callback in order, but pause if a function is marked as a gate.

Current Version: 0.2.0

Tested on: node 0.10.31

Build Status

Annotated Source

A work execution queue that provides tracing and gating. Work functions can have optional callbacks. Timeouts are triggered when execution does not complete within a specified time.

Gating places execution into a serial mode, where all gated work functions must complete in order before other work functions in the queue are called. The gate can be ignored.

Used by Seneca micro-service communication to execute tasks in order. If you haven't heard about Seneca, check out the getting started guide.

Support

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

Gitter chat

Usage

The gate executor provides functionality to pause gated tasks and to quit tasks that exceed a given timeout. The executor can be created with a few options:

var e0 = executor({
  trace: true,              // Error logging trace, default false
  timeout: 150,             // Timout for tasks, default 3333
  error: function() {...},  // A function to wrap all errors in, default noop
  stubs: {		    // Stubs to substitute default node functions
    now: {...},
    setTimeout: {...},
    clearTimeout: {...}
  }
})

When calling the executor with a task, use the following pattern:

e0.execute({
  id: 'a',              // Optional identifier for trace
  fn: function() {...}  // Function to be preformed
  cb: function(err, out) {...}
})

Worker definition

The worker definition object has the following properties:

* _id_:     an identifier string for the worker.
* _desc_:   a description string for the worker.
* _fn_:     the worker function itself; it should accept one argument, a completion callback, which must be called (this in turn then calls the task callback, if any).
* _cb_:     optional callback function, of the form: function(err,result) { ... }.
* _gate_:   this worker is a gate; all subsequent workers will wait for this one to complete.
* _ungate_: this worker will ignore any gates that are active, and so will be executed regardless.

gate-executor's People

Watchers

 avatar

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.