disposable-cls
Version:
Provides disposable continuation local storage for Node.js.
73 lines (72 loc) • 2.23 kB
JavaScript
;
/**
* Represents a context stack item that holds contextual data and associated items
* in scope for the duration of an asynchronous invocation.
*/
var ContextStackItem = (function () {
/**
* Initializes a new context stack item.
*
* @param data An object that will be held in scope.
* @param parent The parent context stack item.
*/
function ContextStackItem(data, parent) {
this._data = data;
this._parent = parent;
this._refCount = 1;
}
Object.defineProperty(ContextStackItem.prototype, "data", {
/**
* Gets the context data for the current context stack item.
*
* @returns An object that contains the context data for the current context stack item.
*/
get: function () {
return this._data;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ContextStackItem.prototype, "parent", {
/**
* Gets the parent context stack item.
*
* @returns A context stack item that is the parent of the current.
*/
get: function () {
return this._parent;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ContextStackItem.prototype, "refCount", {
/**
* Gets the reference count of the current context stack item.
*
* @returns The current reference count.
*/
get: function () {
return this._refCount;
},
enumerable: true,
configurable: true
});
/**
* Adds a reference to the current context stack item.
*
* @returns The current reference count.
*/
ContextStackItem.prototype.addRef = function () {
return ++this._refCount;
};
/**
* Releases a reference from the current context stack item.
*
* @returns The current reference count.
*/
ContextStackItem.prototype.release = function () {
return --this._refCount;
};
return ContextStackItem;
}());
exports.ContextStackItem = ContextStackItem;