Transport disconnect method (#753)

* Prevent reads from piling up

* Implement disconnect() method for all transports
This commit is contained in:
Henri Bergius
2025-08-05 22:46:23 -04:00
committed by GitHub
parent 313c4dbb71
commit 0a7b653ec8
7 changed files with 62 additions and 6 deletions
+10 -2
View File
@@ -4,6 +4,7 @@ import { Utils } from "@meshtastic/core";
export class TransportDeno implements Types.Transport {
private _toDevice: WritableStream<Uint8Array>;
private _fromDevice: ReadableStream<Types.DeviceOutput>;
private connection: Deno.Conn | undefined;
public static async create(hostname: string): Promise<TransportDeno> {
const connection = await Deno.connect({
@@ -14,10 +15,11 @@ export class TransportDeno implements Types.Transport {
}
constructor(connection: Deno.Conn) {
Utils.toDeviceStream.readable.pipeTo(connection.writable);
this.connection = connection;
Utils.toDeviceStream.readable.pipeTo(this.connection.writable);
this._toDevice = Utils.toDeviceStream.writable;
this._fromDevice = connection.readable.pipeThrough(
this._fromDevice = this.connection.readable.pipeThrough(
Utils.fromDeviceStream(),
);
}
@@ -29,4 +31,10 @@ export class TransportDeno implements Types.Transport {
get fromDevice(): ReadableStream<Types.DeviceOutput> {
return this._fromDevice;
}
disconnect(): Promise<void> {
this.connection.close();
this.connection = undefined;
return Promise.resolve();
}
}