CountQueuingStrategy:size() 方法

Baseline 已广泛支持

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

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

CountQueuingStrategy 接口的 size() 方法始终返回 1,因此队列的总大小等于队列中块的数量。

语法

js
size()

参数

无。

返回值

1.

示例

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

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

const size = queuingStrategy.size();

规范

规范
Streams
# ref-for-cqs-size②

浏览器兼容性

另见