Coder Social home page Coder Social logo

queue's Introduction

queue

task queue component for (mobile) browser backed by localstorage

Installation

$ component install pgherveou/queue

Get started

var queue = require('queue')
  .on('error', function(job) {}) // queue error handler
  .on('complete', function(job) {}); // queue success handler

// define a new task
queue
  .define('my-task')
  .online() // check that navigator is online before attempting to process job
  .interval('10s') // replay a failed job every 10sec (default is 2sec)
  .retry(5) // retry up to 5 times
  .timeout('10ms') // task fail if it lasts more than 10ms
  .lifetime('5m') // stop retrying if job is more than 5min old
  .action(function(job, done) {
    // ...
    done(err); // pass an error to the callback if task failed
  });

// load and process jobs persisted in the localstorage
queue.start();

// process a new job
job = queue
  .create('my-task', data)
  .on('error', function() {}) // job error handler
  .on('complete', function() {}) // job success handler

Queue API

require("queue")

get the default queue instance

.createQueue(id)

create a new queue with specific id localstorage keys will be prefixed with queue-[id]

.define(name)

define a new Task with given name

.on([error complete], function(job) {})

Queue is an event emitter, whenever a job fail or complete an error or complete event is triggered

Task Api

.online()

check that navigator is online before attempting to process job

.interval(time)

define the interval between two retries (default is '2sec')

.retry(n)

define max number of retries

.timeout(time)

define task timeout

.lifetime(time)

a job expires if it exceeds cration-time + time

.action(function(job, done))

action to execute receive a job and a callback

License

MIT

queue's People

Contributors

pgherveou avatar

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.