WritableStreamDefaultWriter.closed

Baseline 2022

Newly available

Since June 2022, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

WritableStreamDefaultWriter 接口的只读属性 closed 返回一个 Promise,这个 promise 在流关闭时兑现,而在流抛出错误或者 writer 的锁被释放时拒绝。

一个 Promise

示例

js
const writableStream = new WritableStream({
  start(controller) {
  },
  write(chunk, controller) {
    ...
  },
  close(controller) {
    ...
  },
  abort(err) {
    ...
  }
}, queuingStrategy);

...

const writer = writableStream.getWriter();

..

// check if the stream is closed
writer.closed.then(() => {
  console.log('writer closed');
})

规范

Specification
Streams Standard
# ref-for-default-writer-closed②

浏览器兼容性

BCD tables only load in the browser