ringtail
interval ring for cyclic schedule task
Last updated 3 years ago by andy*() .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ringtail 
SYNC missed versions from official npm registry.

ringtail

ringtail is a JavaScript library to make cyclic task schedule easy and efficient.

Examples

import { Ring, wait, randomStr } from 'ringtail';

const r1 = Ring.of({
  size: 1,
  interval: 1000
});

(async () => {
  await wait(2000) // wait for Ring startup
  console.log('r1 start', Date.now())
  r1.schedule(() => {
    console.log('r1: 1000', Date.now())
  })

  r1.schedule(() => {
    console.log('r1: 2000', Date.now())
  }, 2000)

  r1.schedule(() => {
    console.log('r1: 3000', Date.now())
  }, 3000)
})();

const r2 = Ring.of({
  size: 2,
  interval: 1000
});

(async () => {
  await wait(6000)
  r1.disconnect()
  console.log('r2 start', Date.now())
  r2.schedule(() => {
    console.log('r2: 1000', Date.now())
  })

  r2.schedule(() => {
    console.log('r2: 2000', Date.now())
  }, 2000)

  r2.schedule(() => {
    console.log('r2: 3000', Date.now())
  }, 3000)
})();


const r3 = Ring.of({
  size: 2,
  interval: 1000,
  callback: (v) => {
    console.log('r3:', v, Date.now())
  }
});

(async () => {
  await wait(10000)
  r2.disconnect()
  console.log('r3 start', Date.now())
  const uid = randomStr(10)
  r3.schedule('1000')
  r3.schedule('2000', 2000, uid)
  r3.schedule('3000', 3000)
  r3.cancel(uid)
})();

// r1 start 1513089*739*966
// r1: 1000 1513089*740*976
// r1: 2000 1513089*741*978
// r1: 3000 1513089*742*984
// r2 start 1513089*743*964
// r2: 1000 1513089*744*986
// r2: 2000 1513089*745*992
// r2: 3000 1513089*746*996
// r3 start 1513089*747*964
// r3: 1000 1513089*749*001
// r3: 3000 1513089*751*008

Installation

npm install --save ringtail

Usage

You can import from ringtail:

import { Ring, wait, randomStr } from 'ringtail';
// or
const { Ring, wait, randomStr } = require('ringtail');

Current Tags

  • 0.1.2                                ...           latest (3 years ago)

4 Versions

  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
  • 0.0.1                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |