velocious 1.0.82 → 1.0.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.82",
6
+ "version": "1.0.83",
7
7
  "main": "index.js",
8
8
  "scripts": {
9
9
  "test": "VELOCIOUS_TEST_DIR=../ cd spec/dummy && npx velocious test",
@@ -52,11 +52,15 @@ export default class VelociousHttpServer {
52
52
  }
53
53
 
54
54
  async stopClients() {
55
+ const promises = []
56
+
55
57
  for (const clientCount in this.clients) {
56
58
  const client = this.clients[clientCount]
57
59
 
58
- await client.close()
60
+ promises.push(client.end())
59
61
  }
62
+
63
+ await Promise.all(promises)
60
64
  }
61
65
 
62
66
  stopServer() {
@@ -17,9 +17,11 @@ export default class ServerClient {
17
17
 
18
18
  listen = () => this.socket.on("data", this.onSocketData)
19
19
 
20
- close() {
21
- this.socket.destroy()
22
- this.events.emit("close", this)
20
+ end() {
21
+ return new Promise((resolve) => {
22
+ this.socket.once("close", () => resolve())
23
+ this.socket.end()
24
+ })
23
25
  }
24
26
 
25
27
  onSocketData = (chunk) => {
@@ -37,8 +39,12 @@ export default class ServerClient {
37
39
  this.events.emit("close", this)
38
40
  }
39
41
 
40
- send(data) {
41
- this.logger.debug("Send", data)
42
- this.socket.write(data)
42
+ async send(data) {
43
+ return new Promise((resolve) => {
44
+ this.logger.debug("Send", data)
45
+ this.socket.write(data, () => {
46
+ resolve()
47
+ })
48
+ })
43
49
  }
44
50
  }
@@ -78,7 +78,7 @@ export default class VelociousHttpServerWorker {
78
78
  } else if (command == "clientClose") {
79
79
  const {clientCount} = digs(data, "clientCount")
80
80
 
81
- this.clients[clientCount]?.close()
81
+ this.clients[clientCount]?.end()
82
82
  } else {
83
83
  throw new Error(`Unknown command: ${command}`)
84
84
  }