Sha256: 72fa9f60ff48129143de2e1c1f624cef0d7f41ad55c7d60d94d1014635299607

Contents?: true

Size: 1.81 KB

Versions: 105

Compression:

Stored size: 1.81 KB

Contents

'use strict';

/*<replacement>*/

var pna = require('process-nextick-args');
/*</replacement>*/

// undocumented cb() API, needed for core, not for public API
function destroy(err, cb) {
  var _this = this;

  var readableDestroyed = this._readableState && this._readableState.destroyed;
  var writableDestroyed = this._writableState && this._writableState.destroyed;

  if (readableDestroyed || writableDestroyed) {
    if (cb) {
      cb(err);
    } else if (err && (!this._writableState || !this._writableState.errorEmitted)) {
      pna.nextTick(emitErrorNT, this, err);
    }
    return this;
  }

  // we set destroyed to true before firing error callbacks in order
  // to make it re-entrance safe in case destroy() is called within callbacks

  if (this._readableState) {
    this._readableState.destroyed = true;
  }

  // if this is a duplex stream mark the writable part as destroyed as well
  if (this._writableState) {
    this._writableState.destroyed = true;
  }

  this._destroy(err || null, function (err) {
    if (!cb && err) {
      pna.nextTick(emitErrorNT, _this, err);
      if (_this._writableState) {
        _this._writableState.errorEmitted = true;
      }
    } else if (cb) {
      cb(err);
    }
  });

  return this;
}

function undestroy() {
  if (this._readableState) {
    this._readableState.destroyed = false;
    this._readableState.reading = false;
    this._readableState.ended = false;
    this._readableState.endEmitted = false;
  }

  if (this._writableState) {
    this._writableState.destroyed = false;
    this._writableState.ended = false;
    this._writableState.ending = false;
    this._writableState.finished = false;
    this._writableState.errorEmitted = false;
  }
}

function emitErrorNT(self, err) {
  self.emit('error', err);
}

module.exports = {
  destroy: destroy,
  undestroy: undestroy
};

Version data entries

105 entries across 84 versions & 16 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.18.0 test/dummy/node_modules/fsevents/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.18.0 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.18.2 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.16.1 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.15.2 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.18.4 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.18.1 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.14.0 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/readable-stream/lib/internal/streams/destroy.js
UrgentcareCLI-0.1.1 node_modules/readable-stream/lib/internal/streams/destroy.js
tang-0.2.1 spec/tang_app/node_modules/readable-stream/lib/internal/streams/destroy.js
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/readable-stream/lib/internal/streams/destroy.js
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/readable-stream/lib/internal/streams/destroy.js
ruby2js-4.0.4 lib/tasks/testrails/node_modules/readable-stream/lib/internal/streams/destroy.js
ruby2js-4.0.3 lib/tasks/testrails/node_modules/readable-stream/lib/internal/streams/destroy.js
tang-0.2.0 spec/tang_app/node_modules/readable-stream/lib/internal/streams/destroy.js
tang-0.1.0 spec/tang_app/node_modules/readable-stream/lib/internal/streams/destroy.js
tang-0.0.9 spec/tang_app/node_modules/readable-stream/lib/internal/streams/destroy.js