Simple implementation of deferred object
npm i --save-dev y-deferred
# or
yarn add --dev y-deferred
import Deferred from 'y-deferred'
function test() {
const d = new Deferred()
setTimeout(() => {
d.resolve('done')
}, 1000)
return d
}
async function handleTest() {
const result = await test()
console.log(result) // 'done'
}
handleTest()
Copyright (c) 2017-present, Yuchen Liu