-
Notifications
You must be signed in to change notification settings - Fork 0
/
08_readline_v8_util.js
75 lines (56 loc) · 1.5 KB
/
08_readline_v8_util.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const { EventEmitter } = require("events")
/**
* Core Modules
*/
/**
* 1. Path Modules
*/
const path = require('path');
// console.log('current path', path.basename(__filename))
const dirUploads = path.join(__dirname, 'spec', 'support')
// console.log('spec file path', dirUploads)
/**
* 2. Utility Modules
*/
const utils = require('util')
// utils.log('utilities modules', dirUploads)
/**
* 3. V8 Modules
*/
const v8 = require('v8')
const { getHeapCodeStatistics } = require('v8')
// utils.log('v8 modules', v8.getHeapStatistics())
// console.log('getHeapCodeStatistics', getHeapCodeStatistics())
/**
* 3. V8 Modules
*/
const readLine = require('readline')
const rl = readLine.createInterface({
input: process.stdin,
output: process.stdout
})
// rl.question('How old are u ? ', answer => {
// console.log(`Your are ${answer} year(s) old`)
// process.exit()
// })
// related to file 09_export_modules.js
// const { inc, getCount} = require('./09_export_modules');
// inc()
// inc()
// inc()
// console.log(getCount())
module.exports = (question, done) => {
const answers = [];
const emitter = new EventEmitter()
const questionAnswered = (answer) => {
emitter.emit("answer", answer)
answers.push(answer.trim())
if(answers.length < question.length){
rl.question(question[answers.length], questionAnswered)
} else {
return done(answers)
}
}
rl.question(question[0], questionAnswered)
return emitter
}