 & kErrored) === 0)
      w.errored = err;
    if (r && (r[kState] & kErrored) === 0)
      r.errored = err;
    if (sync)
      ProcessNextTick(emitErrorNT, stream, err);
    else
      emitErrorNT(stream, err);
  }
}
function construct(stream, cb) {
  if (typeof stream._construct !== "function")
    return;
  let { _readableState: r, _writableState: w } = stream;
  if (r)
    r[kState] &= ~kConstructed;
  if (w)
    w[kState] &= ~kConstructed;
  if (stream.once(kConstruct, cb), stream.listenerCount(kConstruct) > 1)
    return;
  ProcessNextTick(constructNT, stream);
}
function constructNT(stream) {
  let called = !1;
  function onConstruct(err) {
    if (called) {
      errorOrDestroy(stream, err ?? @makeErrorWithCode(154));
      return;
    }
    called = !0;
    let { _readableState: r, _writableState: w } = stream, s = w || r;
    if (r)
      r[kState] |= kConstructed;
    if (w)
      w[kState] |= kConstructed;
    if (s.destroyed)
      stream.emit(kDestroy, err);
    else if (err)
      errorOrDestroy(stream, err, !0);
    else
      stream.emit(kConstruct);
  }
  try {
    stream._construct((err) => {
      ProcessNextTick(onConstruct, err);
    });
  } catch (err) {
    ProcessNextTick(onConstruct, err);
  }
}
function isRequest(stream) {
  return stream?.setHeader && typeof stream.abort === "function";
}
function emitCloseLegacy(stream) {
  stream.emit("close");
}
function emitErrorCloseLegacy(stream, err) {
  stream.emit("error", err), ProcessNextTick(emitCloseLegacy, stream);
}
function destroyer(stream, err) {
  if (!stream || isDestroyed(stream))
    return;
  if (!err && !isFinished(stream))
    err = @makeAbortError();
  if (isServerRequest(stream))
    stream.socket = null, stream.destroy(err);
  else if (isRequest(stream))
    stream.abort();
  else if (isRequest(stream.req))
    stream.req.abort();
  else if (typeof stream.destroy === "function")
    stream.destroy(err);
  else if (typeof stream.close === "function")
    stream.close();
  else if (err)
    ProcessNextTick(emitErrorCloseLegacy, stream, err);
  else
    ProcessNextTick(emitCloseLegacy, stream);
  if (!stream.destroyed)
    stream[kIsDestroyed] = !0;
}
$ = {
  construct,
  destroyer,
  destroy,
  undestroy,
  errorOrDestroy
};
return $})

