-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path05.js
More file actions
35 lines (28 loc) · 670 Bytes
/
05.js
File metadata and controls
35 lines (28 loc) · 670 Bytes
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
import EventEmitter from "node:events";
// CONSTANTS
const kReadySymbol = Symbol("ready");
export default class Server extends EventEmitter {
static OHNO = true;
constructor() {
super();
Object.defineProperty(this, kReadySymbol, {
enumerable: false,
configurable: false,
writable: true,
value: false
});
setImmediate(() => {
this.emit("ready");
this[kReadySymbol] = true;
});
}
get isReady() {
return this[kReadySymbol];
}
callMeMaybe() {
if (!this.isReady) {
throw new Error("Server must be ready!");
}
process.stdout.write(Server.OHNO ? "WELL DONE!" : "FOO BAR!");
}
}