1.1.0 • Published 6 years ago
@dkh-dev/single-action v1.1.0
SingleAction
Single action at the same time
Installation
$ yarn add @dkh-dev/single-action
Example
'use strict'
const SingleAction = require('@dkh-dev/single-action')
const getThing = () => new Promise(resolve => {
// resolves in the future
setTimeout(() => resolve(Symbol('something that makes sense')))
})
const main = async () => {
const singleAction = new SingleAction()
const promise1 = getThing()
const promise2 = getThing()
const promise3 = singleAction.do('get thing', getThing)
const promise4 = singleAction.do('get thing', getThing)
console.log(await promise1 === await promise2)
console.log(await promise3 === await promise4)
}
main()