feat: correctly close adb connection

This commit is contained in:
Simon Chan 2022-04-30 21:45:14 +08:00
parent be4dfcd614
commit 7a7f38b3b5
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
14 changed files with 354 additions and 331 deletions

View file

@ -9,7 +9,7 @@ export const AdbSyncDataResponse =
.uint8Array('data', { lengthField: 'dataLength' })
.extra({ id: AdbSyncResponseId.Data as const });
const ResponseTypes = {
const RESPONSE_TYPES = {
[AdbSyncResponseId.Data]: AdbSyncDataResponse,
[AdbSyncResponseId.Done]: new AdbSyncDoneResponse(AdbSyncDataResponse.size),
};
@ -24,7 +24,7 @@ export function adbSyncPull(
await adbSyncWriteRequest(writer, AdbSyncRequestId.Receive, path);
},
async pull(controller) {
const response = await adbSyncReadResponse(stream, ResponseTypes);
const response = await adbSyncReadResponse(stream, RESPONSE_TYPES);
switch (response.id) {
case AdbSyncResponseId.Data:
controller.enqueue(response.data!);
@ -35,7 +35,10 @@ export function adbSyncPull(
default:
throw new Error('Unexpected response id');
}
}
},
cancel() {
throw new Error(`Sync commands don't support cancel.`);
},
}, {
highWaterMark: 16 * 1024,
size(chunk) { return chunk.byteLength; }