functionarrange(name){const tasks =[]
tasks.push(()=>{
console.log(`${name} is notified`)})functiondoSomething(action){
tasks.push(()=>{
console.log(`Start to ${action}`)})returnthis}asyncfunctionexecute(){for(const task of tasks){awaittask()}returnthis}functionwaitFirst(second){
tasks.unshift(()=>newPromise((resolve)=>{setTimeout(resolve, second *1000)}))returnthis}functionwait(second){
tasks.push(()=>newPromise((resolve)=>{setTimeout(resolve, second *1000)}))returnthis}return{do: doSomething,
execute,
waitFirst,
wait,}}arrange('a').execute()// a is notifiedarrange('a').do('b').execute()// a is notified// Start to barrange('a').wait(5).do('b').execute()// a is notified// 5 secend later// Start to barrange('a').waitFirst(5).do('b').execute()// 5 secend later// a is notified// Start to b