1.0.0 • Published 6 years ago
soonish v1.0.0
Soonish
Sometimes you just need to chill for a second.
Installation
npm install soonishUsage
soonish(min, max, callback)
Execute the provided callback after a random delay between min and max milliseconds. If callback is omitted, a function will be returned that can be used in a promise chain to achieve the same effect.
soonish(max, callback)
Execute the provided callback after a random delay between max * 0.5 and max milliseconds. If callback is omitted, a function will be returned that can be used in a promise chain to achieve the same effect.
Callback Example
#!/usr/bin/env node
const soonish = require('soonish')
const debug = require('debug')('test')
debug('before')
soonish(0, 500, () => {
debug('after first')
soonish(500, () => {
debug('after second')
})
})$ DEBUG=test ./example.js
test before +0ms
test after first +172ms
test after second +282msPromised Example
#!/usr/bin/env node
const soonish = require('soonish')
const debug = require('debug')('test')
Promise.resolve()
.then(() => { debug('before') })
.then(soonish(0, 500))
.then(() => { debug('after first') })
.then(soonish(500))
.then(() => { debug('after second') })$ DEBUG=test ./example.js
test before +0ms
test after first +140ms
test after second +309msAny values received will be passed through to the next promise in the chain:
#!/usr/bin/env node
const soonish = require('soonish')
Promise.resolve('hello, world!')
.then(soonish(500))
.then(console.log)$ ./example.js
hello, world!1.0.0
6 years ago