UNPKG

jupyterlab-emrys

Version:

A computational environment for Jupyter. Powered by Emrys

97 lines (96 loc) 2.8 kB
// Copyright (c) Jupyter Development Team. // Distributed under the terms of the Modified BSD License. "use strict"; var phosphor_signaling_1 = require('phosphor-signaling'); /** * A class that monitors activity on a signal. */ var ActivityMonitor = (function () { /** * Construct a new activity monitor. */ function ActivityMonitor(options) { this._timer = -1; this._timeout = -1; this._sender = null; this._args = null; this._isDisposed = false; options.signal.connect(this._onSignalFired, this); this._timeout = options.timeout || 1000; } Object.defineProperty(ActivityMonitor.prototype, "activityStopped", { /** * A signal emitted when activity has ceased. */ get: function () { return Private.activityStoppedSignal.bind(this); }, enumerable: true, configurable: true }); Object.defineProperty(ActivityMonitor.prototype, "timeout", { /** * The timeout associated with the monitor, in milliseconds. */ get: function () { return this._timeout; }, set: function (value) { this._timeout = value; }, enumerable: true, configurable: true }); Object.defineProperty(ActivityMonitor.prototype, "isDisposed", { /** * Test whether the monitor has been disposed. * * #### Notes * This is a read-only property. */ get: function () { return this._isDisposed; }, enumerable: true, configurable: true }); /** * Dispose of the resources used by the activity monitor. */ ActivityMonitor.prototype.dispose = function () { if (this._isDisposed) { return; } this._isDisposed = true; phosphor_signaling_1.clearSignalData(this); }; /** * A signal handler for the monitored signal. */ ActivityMonitor.prototype._onSignalFired = function (sender, args) { var _this = this; clearTimeout(this._timer); this._sender = sender; this._args = args; this._timer = setTimeout(function () { _this.activityStopped.emit({ sender: _this._sender, args: _this._args }); _this._sender = null; _this._args = null; }, this._timeout); }; return ActivityMonitor; }()); exports.ActivityMonitor = ActivityMonitor; /** * A namespace for private data. */ var Private; (function (Private) { /** * A signal emitted when activity has ceased. */ Private.activityStoppedSignal = new phosphor_signaling_1.Signal(); })(Private || (Private = {}));