@intuned/runtime-dev 1.3.24-pipe.9 → 1.3.24-socket.0

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.
@@ -141,6 +141,7 @@ function runAutomationCLI(importFunction) {
141
141
  if (!client.closed) {
142
142
  await client.close();
143
143
  }
144
+ process.exit(0);
144
145
  });
145
146
  _commander.program.parse(process.argv);
146
147
  }
@@ -357,14 +357,9 @@ var require_interfaceClient = __commonJS({
357
357
  var util_1 = require("util");
358
358
  var SocketClient = class _SocketClient {
359
359
  constructor(socket) {
360
- this.dataListener = null;
361
360
  this.socket = socket;
362
- this.closeAbortController = new AbortController();
363
361
  }
364
362
  async sendJSON(data) {
365
- if (this.socket.closed) {
366
- return;
367
- }
368
363
  const dataToSend = JSON.stringify(data);
369
364
  const length = Buffer.byteLength(dataToSend);
370
365
  const buffer = Buffer.alloc(_SocketClient.LENGTH_HEADER_LENGTH + length);
@@ -374,30 +369,21 @@ var require_interfaceClient = __commonJS({
374
369
  }
375
370
  async *receiveJSON() {
376
371
  let buffer = Buffer.alloc(0);
377
- let endListener;
378
- let rejectListener;
379
372
  const endPromise = new Promise((resolve, reject) => {
380
- endListener = () => resolve();
381
- this.socket.once("end", endListener);
382
- rejectListener = (e) => reject(e);
383
- this.socket.once("error", rejectListener);
384
- });
385
- const closePromise = new Promise((resolve) => {
386
- this.closeAbortController.signal.addEventListener("abort", () => resolve());
373
+ this.socket.once("end", () => {
374
+ resolve();
375
+ });
376
+ this.socket.once("error", reject);
387
377
  });
388
378
  while (true) {
389
379
  const chunk = await Promise.race([
390
- new Promise((resolve) => {
391
- this.dataListener = (data2) => {
392
- if (typeof data2 === "string") {
393
- return resolve(Buffer.from(data2));
394
- }
395
- resolve(data2);
396
- };
397
- this.socket.once("data", this.dataListener);
398
- }),
399
- endPromise,
400
- closePromise
380
+ new Promise((resolve) => this.socket.once("data", (data2) => {
381
+ if (typeof data2 === "string") {
382
+ return resolve(Buffer.from(data2));
383
+ }
384
+ resolve(data2);
385
+ })),
386
+ endPromise
401
387
  ]);
402
388
  if (!(chunk instanceof Buffer)) {
403
389
  break;
@@ -418,42 +404,8 @@ var require_interfaceClient = __commonJS({
418
404
  yield JSON.parse(data.toString());
419
405
  }
420
406
  }
421
- async close(mode = "client") {
422
- console.log(`[${process.pid}] Closing socket client`);
423
- if (this.dataListener) {
424
- this.socket.off("data", this.dataListener);
425
- console.log(`[${process.pid}] Removed data listener`);
426
- } else {
427
- console.log(`[${process.pid}] No data listener to remove`);
428
- }
429
- this.closeAbortController.abort();
430
- console.log(`[${process.pid}] Called abort on closeAbortController`);
431
- if (mode === "client") {
432
- console.log(`[${process.pid}] Sending FIN to socket`);
433
- await (0, util_1.promisify)((cb) => this.socket.end(cb))();
434
- const closeResult = await Promise.race([
435
- new Promise((resolve) => this.socket.once("close", () => resolve("closed"))),
436
- new Promise((resolve) => this.socket.once("error", () => resolve("error"))),
437
- (0, promises_1.setTimeout)(3e3, "timeout")
438
- ]);
439
- console.log(`[${process.pid}] Socket close result: ${closeResult}`);
440
- if (closeResult === "timeout") {
441
- console.warn(`[${process.pid}] Socket did not close within timeout, destroying socket`);
442
- this.socket.destroy();
443
- }
444
- return;
445
- }
446
- const receiveEndResult = await Promise.race([
447
- new Promise((resolve) => this.socket.once("end", () => resolve("end"))),
448
- new Promise((resolve) => this.socket.once("error", () => resolve("error"))),
449
- (0, promises_1.setTimeout)(3e3, "timeout")
450
- ]);
451
- console.log(`[${process.pid}] Socket receive end result: ${receiveEndResult}`);
452
- if (receiveEndResult === "end") {
453
- console.log(`[${process.pid}] Socket ended gracefully`);
454
- return;
455
- }
456
- console.log(`[${process.pid}] Socket did not end gracefully, destroying socket`);
407
+ async close() {
408
+ this.socket.end();
457
409
  this.socket.destroy();
458
410
  }
459
411
  get closed() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.3.24-pipe.9",
3
+ "version": "1.3.24-socket.0",
4
4
  "description": "Intuned runtime",
5
5
  "packageManager": "yarn@4.12.0",
6
6
  "main": "./dist/index.js",
@@ -80,7 +80,7 @@
80
80
  "image-size": "^1.1.1",
81
81
  "jsonc-parser": "^3.3.1",
82
82
  "jsonwebtoken": "9.0.2",
83
- "lodash": "4.17.21",
83
+ "lodash": "4.18.1",
84
84
  "milliparsec": "2.3.0",
85
85
  "nanoid": "3",
86
86
  "neverthrow": "6.1.0",