refactor(adb): simplify reading sync responses

This commit is contained in:
Simon Chan 2022-10-07 20:33:11 +08:00
parent c9000c5beb
commit 1486eed3cf
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
18 changed files with 164 additions and 183 deletions

View file

@ -168,7 +168,12 @@ export class AdbPacketDispatcher implements Closeable {
// the device may also respond with two `CLSE` packets.
}
public addIncomingSocketHandler(handler: AdbIncomingSocketHandler): RemoveEventListener {
/**
* Add a handler for incoming socket.
* @param handler A function to call with new incoming sockets. It must return `true` if it accepts the socket.
* @returns A function to remove the handler.
*/
public onIncomingSocket(handler: AdbIncomingSocketHandler): RemoveEventListener {
this._incomingSocketHandlers.add(handler);
const remove = () => {
this._incomingSocketHandlers.delete(handler);
@ -178,7 +183,7 @@ export class AdbPacketDispatcher implements Closeable {
}
private async handleOpen(packet: AdbPacketData) {
// AsyncOperationManager doesn't support get and skip an ID
// `AsyncOperationManager` doesn't support skipping IDs
// Use `add` + `resolve` to simulate this behavior
const [localId] = this.initializers.add<number>();
this.initializers.resolve(localId, undefined);