15.4.0 • Published 5 years ago

@the-/jitter v15.4.0

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

@the-/jitter

npm Version

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, { took })
      // 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

function

class

License

This software is released under the MIT License.

Links

15.4.0

5 years ago

15.2.0

5 years ago

15.1.4

5 years ago

15.1.3

5 years ago

15.1.2

5 years ago

15.1.0

5 years ago

15.0.3

5 years ago

15.0.2

5 years ago