Back to Content

WritableStream: abort() method

files/en-us/web/api/writablestream/abort/index.md

latest1012 B
Original Source

{{APIRef("Streams")}}{{AvailableInWorkers}}

The abort() method of the {{domxref("WritableStream")}} interface aborts the stream, signaling that the producer can no longer successfully write to the stream and it is to be immediately moved to an error state, with any queued writes discarded.

Syntax

js-nolint
abort(reason)

Parameters

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

Return value

A {{jsxref("Promise")}}, which fulfills with undefined.

Exceptions

  • {{jsxref("TypeError")}}
    • : The stream you are trying to abort is not a {{domxref("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();

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}