UNPKG

1.94 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Jupyter Development Team.
3// Distributed under the terms of the Modified BSD License.
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.ActivityMonitor = void 0;
6const signaling_1 = require("@lumino/signaling");
7/**
8 * A class that monitors activity on a signal.
9 */
10class ActivityMonitor {
11 /**
12 * Construct a new activity monitor.
13 */
14 constructor(options) {
15 this._timer = -1;
16 this._timeout = -1;
17 this._isDisposed = false;
18 this._activityStopped = new signaling_1.Signal(this);
19 options.signal.connect(this._onSignalFired, this);
20 this._timeout = options.timeout || 1000;
21 }
22 /**
23 * A signal emitted when activity has ceased.
24 */
25 get activityStopped() {
26 return this._activityStopped;
27 }
28 /**
29 * The timeout associated with the monitor, in milliseconds.
30 */
31 get timeout() {
32 return this._timeout;
33 }
34 set timeout(value) {
35 this._timeout = value;
36 }
37 /**
38 * Test whether the monitor has been disposed.
39 *
40 * #### Notes
41 * This is a read-only property.
42 */
43 get isDisposed() {
44 return this._isDisposed;
45 }
46 /**
47 * Dispose of the resources used by the activity monitor.
48 */
49 dispose() {
50 if (this._isDisposed) {
51 return;
52 }
53 this._isDisposed = true;
54 signaling_1.Signal.clearData(this);
55 }
56 /**
57 * A signal handler for the monitored signal.
58 */
59 _onSignalFired(sender, args) {
60 clearTimeout(this._timer);
61 this._sender = sender;
62 this._args = args;
63 this._timer = setTimeout(() => {
64 this._activityStopped.emit({
65 sender: this._sender,
66 args: this._args
67 });
68 }, this._timeout);
69 }
70}
71exports.ActivityMonitor = ActivityMonitor;
72//# sourceMappingURL=activitymonitor.js.map
\No newline at end of file