@platformatic/itc
Advanced tools
+15
-8
@@ -182,3 +182,3 @@ import { Unpromise } from '@watchable/unpromise' | ||
| export class ITC extends EventEmitter { | ||
| #requestEmitter | ||
| #waitingRequests | ||
| #handlers | ||
@@ -204,3 +204,3 @@ #listening | ||
| this.port = port | ||
| this.#requestEmitter = new EventEmitter() | ||
| this.#waitingRequests = new Map() | ||
| this.#handlers = new Map() | ||
@@ -212,5 +212,2 @@ this.#listening = false | ||
| // Make sure the emitter handle a lot of listeners at once before raising a warning | ||
| this.#requestEmitter.setMaxListeners(1e3) | ||
| /* | ||
@@ -249,2 +246,3 @@ There some contexts in which a message is sent and the event loop empties up while waiting for a response. | ||
| let reqId | ||
| try { | ||
@@ -256,5 +254,7 @@ this._enableKeepAlive() | ||
| const responsePromise = once(this.#requestEmitter, request.reqId).then(([response]) => response) | ||
| const promiseWithResolvers = Promise.withResolvers() | ||
| reqId = request.reqId | ||
| this.#waitingRequests.set(request.reqId, promiseWithResolvers) | ||
| const { error, data } = await Unpromise.race([responsePromise, this.#closePromise]) | ||
| const { error, data } = await Unpromise.race([promiseWithResolvers.promise, this.#closePromise]) | ||
@@ -264,2 +264,4 @@ if (error !== null) throw error | ||
| } finally { | ||
| // Clean up the waiting requests map even if an error occurred | ||
| this.#waitingRequests.delete(reqId) | ||
| this._manageKeepAlive() | ||
@@ -397,3 +399,8 @@ } | ||
| _emitResponse (response) { | ||
| this.#requestEmitter.emit(response.reqId, response) | ||
| const pending = this.#waitingRequests.get(response.reqId) | ||
| if (!pending) { | ||
| return | ||
| } | ||
| pending.resolve(response) | ||
| } | ||
@@ -400,0 +407,0 @@ |
+1
-1
| { | ||
| "name": "@platformatic/itc", | ||
| "version": "3.14.0", | ||
| "version": "3.15.0", | ||
| "description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
26037
0.48%404
1.76%2
-33.33%