open-vault/ui/app/helpers/-date-base.js
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

45 lines
1,008 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { run } from '@ember/runloop';
import Helper from '@ember/component/helper';
import Ember from 'ember';
export default Helper.extend({
disableInterval: false,
compute(value, { interval }) {
if (Ember.testing) {
// issues with flaky test, suspect it has to the do with the run loop not being cleared as intended farther down.
return;
}
if (this.disableInterval) {
return;
}
this.clearTimer();
if (interval) {
/*
* NOTE: intentionally a setTimeout so tests do not block on it
* as the run loop queue is never clear so tests will stay locked waiting
* for queue to clear.
*/
this.intervalTimer = setTimeout(() => {
run(() => this.recompute());
}, parseInt(interval, 10));
}
},
clearTimer() {
clearTimeout(this.intervalTimer);
},
destroy() {
this.clearTimer();
this._super(...arguments);
},
});