-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
39 lines (33 loc) · 1009 Bytes
/
test.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
class STD {
constructor() {
this.Promises = [];
this.resolves = [];
this.rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})
}
/* --------------------------------- then函数 --------------------------------- */
then(question, func) {
const promise = () => {
return new Promise((resolve, reject) => {
this.resolves.push(resolve)
this.rl.question(question, func)
})
}
this.Promises.push(promise)
return this;
}
/* ---------------------------- Promise的resolve函数 --------------------------- */
resolve() {
this.resolves.pop()();
}
/* ------------------------------- then之后run函数 ------------------------------ */
async run() {
for (const promise of this.Promises) {
await promise()
}
this.rl.close()
}
}
exports.STD = STD