Protocol.connect() can automatically call Transport.start()

This commit is contained in:
Justin Spahr-Summers 2024-10-16 13:10:31 +01:00
commit 83a43fda1e
No known key found for this signature in database
2 changed files with 5 additions and 6 deletions

View file

@ -83,7 +83,7 @@ export class Protocol<
}
/**
* Attaches to the given transport and starts listening for messages.
* Attaches to the given transport, starts it, and starts listening for messages.
*
* The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
*/
@ -106,6 +106,8 @@ export class Protocol<
this._onnotification(message);
}
};
await this._transport.start();
}
private _onclose(): void {

View file

@ -8,6 +8,8 @@ export interface Transport {
* Starts processing messages on the transport, including any connection steps that might need to be taken.
*
* This method should only be called after callbacks are installed, or else messages may be lost.
*
* NOTE: This method should not be called explicitly when using Client, Server, or Protocol classes, as they will implicitly call start().
*/
start(): Promise<void>;