==== Sample ====
async function wait1 (): Promise {
return new Promise((resolve) => {
setTimeout(() => {
console.log("WAIT1")
resolve()
}, 1000)
})
}
async function wait2 (): Promise {
return new Promise((resolve) => {
setTimeout(() => {
console.log("WAIT2")
resolve()
}, 2000)
})
}
async function wait3 (): Promise {
return new Promise((resolve) => {
setTimeout(() => {
console.log("WAIT3")
resolve()
}, 3000)
})
}
async function waitForString (s: string, timeoutSec: number): Promise<[string, number]> {
return new Promise((resolve) => {
setTimeout(() => {
console.log("Promise", s)
resolve([s, timeoutSec])
}, timeoutSec*1000)
})
}
async function promisePrac2() {
let second = 1
setInterval(() => {
console.log("Second: ", second++)
}, 1000)
const strings = ["a", "b", "c"]
let x = 1
const promises = strings.map(async s => await waitForString(s, x++))
await Promise.all(promises)
}
async function promisePrac() {
let second = 1
setInterval(() => {
console.log("Second: ", second++)
}, 1000)
// await wait1()
// await wait2()
// await wait3()
const promises = [wait1(), wait2(), wait3()]
await Promise.all([wait1(), wait2(), wait3()])
}
promisePrac2()