CountQueuingStrategy

Baseline 已广泛支持

此功能已成熟,并可在多种设备和浏览器版本上使用。自 ⁨2019 年 1 月⁩起,它已在所有浏览器中可用。

注意:此功能在 Web Workers 中可用。

Streams API 的 CountQueuingStrategy 接口提供了一个内置的块计数排队策略,可用于构建流时使用。

构造函数

CountQueuingStrategy()

创建一个新的 CountQueuingStrategy 对象实例。

实例属性

CountQueuingStrategy.highWaterMark 只读

在应用背压之前,内部队列中可以包含的块总数。

实例方法

CountQueuingStrategy.size()

始终返回 1

示例

js
const queueingStrategy = new CountQueuingStrategy({ highWaterMark: 1 });

const writableStream = new WritableStream(
  {
    // Implement the sink
    write(chunk) {
      // …
    },
    close() {
      // …
    },
    abort(err) {
      console.log("Sink error:", err);
    },
  },
  queueingStrategy,
);

const size = queueingStrategy.size();

规范

规范
Streams
# cqs-class

浏览器兼容性

另见