summaryrefslogtreecommitdiff
path: root/cli/rt/20_streams_queuing_strategy.js
blob: cbd30664fa8dc21a16a7f3cd3a9b08c7886e828e (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
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.

((window) => {
  const { customInspect } = window.__bootstrap.console;

  class CountQueuingStrategy {
    constructor({ highWaterMark }) {
      this.highWaterMark = highWaterMark;
    }

    size() {
      return 1;
    }

    [customInspect]() {
      return `${this.constructor.name} { highWaterMark: ${
        String(this.highWaterMark)
      }, size: f }`;
    }
  }

  Object.defineProperty(CountQueuingStrategy.prototype, "size", {
    enumerable: true,
  });

  class ByteLengthQueuingStrategy {
    constructor({ highWaterMark }) {
      this.highWaterMark = highWaterMark;
    }

    size(chunk) {
      return chunk.byteLength;
    }

    [customInspect]() {
      return `${this.constructor.name} { highWaterMark: ${
        String(this.highWaterMark)
      }, size: f }`;
    }
  }

  Object.defineProperty(ByteLengthQueuingStrategy.prototype, "size", {
    enumerable: true,
  });

  window.__bootstrap.queuingStrategy = {
    CountQueuingStrategy,
    ByteLengthQueuingStrategy,
  };
})(this);