Browse Source

Prevent reads from piling up

pull/753/head
Henri Bergius 11 months ago
parent
commit
baf75c5b9b
  1. 14
      packages/transport-http/src/transport.ts

14
packages/transport-http/src/transport.ts

@ -6,6 +6,7 @@ export class TransportHTTP implements Types.Transport {
private url: string;
private receiveBatchRequests: boolean;
private fetchInterval: number;
private fetching: boolean;
public static async create(
address: string,
@ -23,6 +24,7 @@ export class TransportHTTP implements Types.Transport {
this.url = url;
this.receiveBatchRequests = false;
this.fetchInterval = 3000;
this.fetching = false;
this._toDevice = new WritableStream<Uint8Array>({
write: async (chunk) => {
@ -39,7 +41,17 @@ export class TransportHTTP implements Types.Transport {
});
setInterval(async () => {
await this.readFromRadio(controller);
if (this.fetching) {
// We still have the previous request open
return;
}
this.fetching = true;
try {
await this.readFromRadio(controller);
} catch (e) {
// TODO: Emit disconnection events for certain types of errors
}
this.fetching = false;
}, this.fetchInterval);
}

Loading…
Cancel
Save