mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 09:49:24 +02:00
fix(stream): let PushReadableStream
handle cancelled streams.
Also add tests Relates to #648
This commit is contained in:
parent
a1c6450b2f
commit
fb4507ddc5
10 changed files with 1267 additions and 100 deletions
|
@ -138,20 +138,7 @@ export class AdbDaemonSocketController
|
|||
}
|
||||
|
||||
async enqueue(data: Uint8Array) {
|
||||
// Consumers can `cancel` the `readable` if they are not interested in future data.
|
||||
// Throw away the data if that happens.
|
||||
if (this.#readableController.abortSignal.aborted) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await this.#readableController.enqueue(data);
|
||||
} catch (e) {
|
||||
if (this.#readableController.abortSignal.aborted) {
|
||||
return;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
await this.#readableController.enqueue(data);
|
||||
}
|
||||
|
||||
public ack(bytes: number) {
|
||||
|
@ -182,23 +169,13 @@ export class AdbDaemonSocketController
|
|||
}
|
||||
|
||||
dispose() {
|
||||
try {
|
||||
this.#readableController.close();
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
|
||||
this.#readableController.close();
|
||||
this.#closedPromise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A duplex stream representing a socket to ADB daemon.
|
||||
*
|
||||
* To close it, call either `socket.close()`,
|
||||
* `socket.readable.cancel()`, `socket.readable.getReader().cancel()`,
|
||||
* `socket.writable.abort()`, `socket.writable.getWriter().abort()`,
|
||||
* `socket.writable.close()` or `socket.writable.getWriter().close()`.
|
||||
*/
|
||||
export class AdbDaemonSocket implements AdbDaemonSocketInfo, AdbSocket {
|
||||
#controller: AdbDaemonSocketController;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue