@jupyterlab/coreutils
Version:
JupyterLab - Core Utilities
72 lines • 1.94 kB
JavaScript
"use strict";
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActivityMonitor = void 0;
const signaling_1 = require("@lumino/signaling");
/**
* A class that monitors activity on a signal.
*/
class ActivityMonitor {
/**
* Construct a new activity monitor.
*/
constructor(options) {
this._timer = -1;
this._timeout = -1;
this._isDisposed = false;
this._activityStopped = new signaling_1.Signal(this);
options.signal.connect(this._onSignalFired, this);
this._timeout = options.timeout || 1000;
}
/**
* A signal emitted when activity has ceased.
*/
get activityStopped() {
return this._activityStopped;
}
/**
* The timeout associated with the monitor, in milliseconds.
*/
get timeout() {
return this._timeout;
}
set timeout(value) {
this._timeout = value;
}
/**
* Test whether the monitor has been disposed.
*
* #### Notes
* This is a read-only property.
*/
get isDisposed() {
return this._isDisposed;
}
/**
* Dispose of the resources used by the activity monitor.
*/
dispose() {
if (this._isDisposed) {
return;
}
this._isDisposed = true;
signaling_1.Signal.clearData(this);
}
/**
* A signal handler for the monitored signal.
*/
_onSignalFired(sender, args) {
clearTimeout(this._timer);
this._sender = sender;
this._args = args;
this._timer = setTimeout(() => {
this._activityStopped.emit({
sender: this._sender,
args: this._args
});
}, this._timeout);
}
}
exports.ActivityMonitor = ActivityMonitor;
//# sourceMappingURL=activitymonitor.js.map