function people(name){
this.name = name
let queue = []
let status = 'waiting'
const execute = function(){
let task = queue.shift()
while(task){
// console.log(task)
task()
task = queue.shift()
}
}
this.work = function(){
queue.push(()=> {
console.log("I'm working")
})
// if(status == 'waiting'){
// execute()
// }
return this
}
this.eat = function(food){
queue.push(()=> {
console.log("I'm eating "+ food)
})
// if(status == 'waiting'){
// execute()
// }
return this
}
this.sleep = function(delay){
status = 'pending'
setTimeout(()=>{
status = 'waiting'
console.log('deal ' + delay + ' seconds later')
// execute()
}, delay * 1000)
return this
}
this.sleepBefore = function(delay){
console.log('start ' + delay + ' seconds later')
}
if(status == 'waiting'){
execute()
}
return this
}
people('david').work().sleep(3).eat('banana').sleepBefore(5)
console