function wait() {
const p = () => ({
value: new Promise(resolve => setTimeout(() => resolve(), 3000))
})
let state = {
next: () => {
state.next = programPart
return p()
}
}
function programPart() {
console.log("unlocked1")
state.next = programPart2
return p()
}
function programPart2() {
console.log("unlocked2")
console.log("it\"s sync!!")
return {
value: void 0
}
}
return state
}
how should this function be called?