disposable-cls
Version:
Provides disposable continuation local storage for Node.js.
49 lines (48 loc) • 1.49 kB
JavaScript
;
/**
* Represents a very simple object.
*/
var SimpleMockObject = (function () {
function SimpleMockObject() {
}
return SimpleMockObject;
}());
exports.SimpleMockObject = SimpleMockObject;
/**
* Represents a very simple 'disposable' object.
*/
var SimpleDisposableMockObject = (function () {
/**
* Initializes a new instance of a disposable mock object.
*
* @param disposeCallback The callback that will be called when the current object
* is being disposed.
*/
function SimpleDisposableMockObject(disposeCallback) {
this.disposeCallback = disposeCallback;
this._id = Math.floor(Math.random());
}
Object.defineProperty(SimpleDisposableMockObject.prototype, "id", {
/**
* Gets the identifier if the current mock object.
*
* @returns A number that uniquely identifies this mock object.
*/
get: function () {
return this._id;
},
enumerable: true,
configurable: true
});
/**
* A dispose method that should be invoked by the context stack then this mock object
* goes out of scope.
*/
SimpleDisposableMockObject.prototype.dispose = function () {
if (this.disposeCallback) {
this.disposeCallback();
}
};
return SimpleDisposableMockObject;
}());
exports.SimpleDisposableMockObject = SimpleDisposableMockObject;