WritableStream: phương thức abort()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2022.

Note: This feature is available in Web Workers.

Phương thức abort() của giao diện WritableStream hủy bỏ luồng, báo hiệu rằng nhà sản xuất không còn có thể ghi thành công vào luồng nữa và luồng đó sẽ ngay lập tức được chuyển sang trạng thái lỗi, mọi thao tác ghi trong hàng đợi sẽ bị loại bỏ.

Cú pháp

js
abort(reason)

Parameters

reason

A string providing a human-readable reason for the abort.

Return value

A Promise, which fulfills with undefined.

Exceptions

TypeError

The stream you are trying to abort is not a WritableStream, or it is locked.

Examples

js
const writableStream = new WritableStream(
  {
    write(chunk) {
      // …
    },
    close() {
      // …
    },
    abort(err) {
      // …
    },
  },
  queuingStrategy,
);

// …

// abort the stream later on, when required
writableStream.abort();

Thông số kỹ thuật

Specification
Streams
# ref-for-ws-abort③

Khả năng tương thích của trình duyệt