summaryrefslogtreecommitdiff
path: root/cli/js/web/streams/writable-stream-default-controller.ts
blob: 181edede8f8cd3bdec90d1bdd219c2a8b1a897a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// TODO reenable this code when we enable writableStreams and transport types
// // Forked from https://github.com/stardazed/sd-streams/tree/8928cf04b035fd02fb1340b7eb541c76be37e546
// // Copyright (c) 2018-Present by Arthur Langereis - @zenmumbler MIT

// /**
//  * streams/writable-stream-default-controller - WritableStreamDefaultController class implementation
//  * Part of Stardazed
//  * (c) 2018-Present by Arthur Langereis - @zenmumbler
//  * https://github.com/stardazed/sd-streams
//  */

// /* eslint-disable @typescript-eslint/no-explicit-any */
// // TODO reenable this lint here

// import * as ws from "./writable-internals.ts";
// import * as shared from "./shared-internals.ts";
// import * as q from "./queue-mixin.ts";
// import { Queue } from "./queue.ts";
// import { QueuingStrategySizeCallback } from "../dom_types.d.ts";

// export class WritableStreamDefaultController<InputType>
//   implements ws.WritableStreamDefaultController<InputType> {
//   [ws.abortAlgorithm_]: ws.AbortAlgorithm;
//   [ws.closeAlgorithm_]: ws.CloseAlgorithm;
//   [ws.controlledWritableStream_]: ws.WritableStream<InputType>;
//   [ws.started_]: boolean;
//   [ws.strategyHWM_]: number;
//   [ws.strategySizeAlgorithm_]: QueuingStrategySizeCallback<InputType>;
//   [ws.writeAlgorithm_]: ws.WriteAlgorithm<InputType>;

//   [q.queue_]: Queue<q.QueueElement<ws.WriteRecord<InputType> | "close">>;
//   [q.queueTotalSize_]: number;

//   constructor() {
//     throw new TypeError();
//   }

//   error(e?: shared.ErrorResult): void {
//     if (!ws.isWritableStreamDefaultController(this)) {
//       throw new TypeError();
//     }
//     const state = this[ws.controlledWritableStream_][shared.state_];
//     if (state !== "writable") {
//       return;
//     }
//     ws.writableStreamDefaultControllerError(this, e);
//   }

//   [ws.abortSteps_](reason: shared.ErrorResult): Promise<void> {
//     const result = this[ws.abortAlgorithm_](reason);
//     ws.writableStreamDefaultControllerClearAlgorithms(this);
//     return result;
//   }

//   [ws.errorSteps_](): void {
//     q.resetQueue(this);
//   }
// }

// export function setUpWritableStreamDefaultControllerFromUnderlyingSink<
//   InputType
// >(
//   stream: ws.WritableStream<InputType>,
//   underlyingSink: ws.WritableStreamSink<InputType>,
//   highWaterMark: number,
//   sizeAlgorithm: QueuingStrategySizeCallback<InputType>
// ): void {
//   // Assert: underlyingSink is not undefined.
//   const controller = Object.create(
//     WritableStreamDefaultController.prototype
//   ) as WritableStreamDefaultController<InputType>;

//   const startAlgorithm = function(): any {
//     return shared.invokeOrNoop(underlyingSink, "start", [controller]);
//   };
//   const writeAlgorithm = shared.createAlgorithmFromUnderlyingMethod(
//     underlyingSink,
//     "write",
//     [controller]
//   );
//   const closeAlgorithm = shared.createAlgorithmFromUnderlyingMethod(
//     underlyingSink,
//     "close",
//     []
//   );
//   const abortAlgorithm = shared.createAlgorithmFromUnderlyingMethod(
//     underlyingSink,
//     "abort",
//     []
//   );
//   ws.setUpWritableStreamDefaultController(
//     stream,
//     controller,
//     startAlgorithm,
//     writeAlgorithm,
//     closeAlgorithm,
//     abortAlgorithm,
//     highWaterMark,
//     sizeAlgorithm
//   );
// }