1.0.2 • Published 5 years ago

the-jitter v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

the-jitter

Build Status npm Version JS Standard

Random delay timer

Installation

$ npm install the-jitter --save

Usage

'use strict'

const { TheJitter } = require('the-jitter')

async function tryExample () {
  const jitter = new TheJitter({
    maxCount: 100,
    maxInterval: 1000,
  })

  async function doSomething (i) {
    console.log('Method called', i)
    const at = new Date()
    await jitter.handle(async () => {
      const took = new Date() - at
      console.log(`Jitter delay=${at}ms`, i)
      // called with some delay
      /* ... */
    })
    console.log('Method Finished', i)
  }

  for (let i = 0; i < 1000; i++) {
    void doSomething(i)
  }
}

tryExample().catch((err) => console.error(err))

API Guide

License

This software is released under the MIT License.

Links

1.0.2

5 years ago

1.0.1

5 years ago