Use more consistent start/stop pattern
This commit is contained in:
parent
488cc416cf
commit
b0a2772889
2 changed files with 17 additions and 12 deletions
|
@ -36,6 +36,10 @@ export default class DecryptionFailureTracker {
|
||||||
// [eventId]: true
|
// [eventId]: true
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set to an interval ID when `start` is called
|
||||||
|
checkInterval = null;
|
||||||
|
trackInterval = null;
|
||||||
|
|
||||||
// Spread the load on `Analytics` by sending at most 1 event per
|
// Spread the load on `Analytics` by sending at most 1 event per
|
||||||
// `TRACK_INTERVAL_MS`.
|
// `TRACK_INTERVAL_MS`.
|
||||||
static TRACK_INTERVAL_MS = 1000;
|
static TRACK_INTERVAL_MS = 1000;
|
||||||
|
@ -82,27 +86,28 @@ export default class DecryptionFailureTracker {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start checking for and tracking failures.
|
* Start checking for and tracking failures.
|
||||||
* @return {function} a function that clears state and causes DFT to stop checking for
|
|
||||||
* and tracking failures.
|
|
||||||
*/
|
*/
|
||||||
start() {
|
start() {
|
||||||
const checkInterval = setInterval(
|
this.checkInterval = setInterval(
|
||||||
() => this.checkFailures(Date.now()),
|
() => this.checkFailures(Date.now()),
|
||||||
DecryptionFailureTracker.CHECK_INTERVAL_MS,
|
DecryptionFailureTracker.CHECK_INTERVAL_MS,
|
||||||
);
|
);
|
||||||
|
|
||||||
const trackInterval = setInterval(
|
this.trackInterval = setInterval(
|
||||||
() => this.trackFailure(),
|
() => this.trackFailure(),
|
||||||
DecryptionFailureTracker.TRACK_INTERVAL_MS,
|
DecryptionFailureTracker.TRACK_INTERVAL_MS,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
/**
|
||||||
clearInterval(checkInterval);
|
* Clear state and stop checking for and tracking failures.
|
||||||
clearInterval(trackInterval);
|
*/
|
||||||
|
stop() {
|
||||||
|
clearInterval(this.checkInterval);
|
||||||
|
clearInterval(this.trackInterval);
|
||||||
|
|
||||||
this.failures = [];
|
this.failures = [];
|
||||||
this.failuresToTrack = [];
|
this.failuresToTrack = [];
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1318,10 +1318,10 @@ export default React.createClass({
|
||||||
// tracked events across sessions.
|
// tracked events across sessions.
|
||||||
// dft.loadTrackedEventHashMap();
|
// dft.loadTrackedEventHashMap();
|
||||||
|
|
||||||
const stopDft = dft.start();
|
dft.start();
|
||||||
|
|
||||||
// When logging out, stop tracking failures and destroy state
|
// When logging out, stop tracking failures and destroy state
|
||||||
cli.on("Session.logged_out", stopDft);
|
cli.on("Session.logged_out", () => dft.stop());
|
||||||
cli.on("Event.decrypted", (e) => dft.eventDecrypted(e));
|
cli.on("Event.decrypted", (e) => dft.eventDecrypted(e));
|
||||||
|
|
||||||
const krh = new KeyRequestHandler(cli);
|
const krh = new KeyRequestHandler(cli);
|
||||||
|
|
Loading…
Reference in a new issue