nighthouse
Advanced tools
Comparing version 2.1.2 to 2.1.3
@@ -142,5 +142,25 @@ "use strict"; | ||
async *receiveStreaming(id) { | ||
while (true) { | ||
yield await this.receiveSingle(id); | ||
// We use a queue of promises instead of naively performing `receiveSingle` | ||
// in a loop to deal with the scenario where the server sends messages | ||
// faster than we clients can process them. | ||
try { | ||
const nextPromises = []; | ||
const pushPromise = () => { | ||
const deferred = new deferred_1.Deferred(); | ||
this.responseHandlers.set(id, deferred); | ||
nextPromises.push(deferred.promise.then(message => { | ||
pushPromise(); | ||
return message; | ||
})); | ||
}; | ||
pushPromise(); | ||
while (true) { | ||
const promise = nextPromises.shift(); | ||
yield await promise; | ||
} | ||
} | ||
finally { | ||
this.logger.trace(`Deleting stream handler for ${id}`); | ||
this.responseHandlers.delete(id); | ||
} | ||
} | ||
@@ -147,0 +167,0 @@ /** Handles a server message. */ |
{ | ||
"name": "nighthouse", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Lightweight Project Lighthouse client for JavaScript", | ||
@@ -5,0 +5,0 @@ "workspaces": [ |
@@ -165,4 +165,27 @@ import { Transport } from "./transport"; | ||
private async* receiveStreaming(id: number): AsyncIterable<ServerMessage<unknown>> { | ||
while (true) { | ||
yield await this.receiveSingle(id); | ||
// We use a queue of promises instead of naively performing `receiveSingle` | ||
// in a loop to deal with the scenario where the server sends messages | ||
// faster than we clients can process them. | ||
try { | ||
const nextPromises = []; | ||
const pushPromise = () => { | ||
const deferred = new Deferred<ServerMessage<unknown>>(); | ||
this.responseHandlers.set(id, deferred); | ||
nextPromises.push(deferred.promise.then(message => { | ||
pushPromise(); | ||
return message; | ||
})); | ||
} | ||
pushPromise(); | ||
while (true) { | ||
const promise = nextPromises.shift(); | ||
yield await promise; | ||
} | ||
} finally { | ||
this.logger.trace(`Deleting stream handler for ${id}`); | ||
this.responseHandlers.delete(id); | ||
} | ||
@@ -169,0 +192,0 @@ } |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
127902
1524