let bar = null
let fooPromise = null
const foo = () => new Promise(resolve => setTimeout(() => {
bar = 123
resolve(4000)
}, 5000))
const func1 = async (id) => {
if (fooPromise === null) {
fooPromise = foo()
}
console.log(id, 'is awaiting')
// await fooPromise
// console.log(id, bar)
console.log(id, await fooPromise)
}
Promise.allSettled([func1(1), func1(2)]).then(() => {
console.log('done')
func1(3).then(() => {
console.log('done2')
})
})
To embed this program on your website, copy the following code and paste it into your website's HTML: