-
Notifications
You must be signed in to change notification settings - Fork 0
/
lazyMan.js
40 lines (40 loc) · 936 Bytes
/
lazyMan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function lazeMan(name) {
let task = []
let fn = () => {
console.log('hello,' + name)
next()
};
task.push(fn)
let next = () => {
let a = task.shift()
a && a()
}
setTimeout(() => {
next()
})
let api = {
sleep: (time) =>{
let fun = () => {
setTimeout(() => {console.log('wait ' + time); next()},time)
}
task.push(fun)
return api
},
eat: (something)=> {
let fun = () => {
console.log('Eat ' + something)
next()
}
task.push(fun)
return api
},
sleepFirst: (time) => {
let fun = () => {
setTimeout(() => {console.log('first wait' + time); next()}, time)
}
task.unshift(fun)
return api
}
}
return api
}