Skip to content

Commit

Permalink
Merge pull request #105 from MattiasBuelens/rewrite-transform-stream
Browse files Browse the repository at this point in the history
Rewrite TransformStream using the public API
  • Loading branch information
MattiasBuelens committed Nov 17, 2021
2 parents e10fb3c + c9d1970 commit 4f231a4
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 81 deletions.
1 change: 1 addition & 0 deletions etc/web-streams-polyfill.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
export interface AbortSignal {
readonly aborted: boolean;
addEventListener(type: 'abort', listener: () => void): void;
readonly reason?: any;
removeEventListener(type: 'abort', listener: () => void): void;
}

Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"@ungap/promise-all-settled": "^1.1.2",
"abort-controller": "^3.0.0",
"eslint": "^7.32.0",
"jasmine": "^3.9.0",
"micromatch": "^4.0.4",
Expand Down
7 changes: 6 additions & 1 deletion src/lib/abort-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export interface AbortSignal {
*/
readonly aborted: boolean;

/**
* The abort reason.
*/
readonly reason?: any;

/**
* Add an event listener to be triggered when this signal becomes aborted.
*/
Expand Down Expand Up @@ -51,7 +56,7 @@ export function isAbortSignal(value: unknown): value is AbortSignal {
export interface AbortController {
readonly signal: AbortSignal;

abort(): void;
abort(reason?: any): void;
}

interface AbortControllerConstructor {
Expand Down
14 changes: 2 additions & 12 deletions src/lib/readable-stream/default-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,23 +307,13 @@ export function ReadableStreamDefaultControllerGetDesiredSize(
export function ReadableStreamDefaultControllerHasBackpressure(
controller: ReadableStreamDefaultController<any>
): boolean {
if (ReadableStreamDefaultControllerShouldCallPull(controller)) {
return false;
}

return true;
return !ReadableStreamDefaultControllerShouldCallPull(controller);
}

export function ReadableStreamDefaultControllerCanCloseOrEnqueue(
controller: ReadableStreamDefaultController<any>
): boolean {
const state = controller._controlledReadableStream._state;

if (!controller._closeRequested && state === 'readable') {
return true;
}

return false;
return !controller._closeRequested && controller._controlledReadableStream._state === 'readable';
}

export function SetUpReadableStreamDefaultController<R>(stream: ReadableStream<R>,
Expand Down
Loading

0 comments on commit 4f231a4

Please sign in to comment.