import { b as _defineProperty } from '../_rollupPluginBabelHelpers-9wjJaosZ.js';
import { later, cancel } from '@ember/runloop';

class Timer {
  constructor(callback, timeMs) {
    // In a browser this is a number, but in node it's a NodeJS.Time (a
    // class). We don't care about this difference.
    _defineProperty(this, "id", void 0);
    _defineProperty(this, "callback", void 0);
    _defineProperty(this, "finishTime", void 0);
    _defineProperty(this, "timeRemaining", void 0);
    _defineProperty(this, "pause", () => {
      cancel(this.id);
      this.id = undefined;
      this.timeRemaining = (this.finishTime || 0) - Date.now();
    });
    _defineProperty(this, "resume", () => {
      this.id = later(this.finish, this.timeRemaining);
      this.finishTime = Date.now() + (this.timeRemaining || 0);
      this.timeRemaining = undefined;
    });
    _defineProperty(this, "clear", () => {
      cancel(this.id);
      this.id = undefined;
      this.callback = undefined;
      this.finishTime = undefined;
      this.timeRemaining = undefined;
    });
    _defineProperty(this, "finish", () => {
      if (this.callback) {
        this.callback();
      }
      this.clear();
    });
    this.id = later(this.finish, timeMs);
    this.callback = callback;
    this.finishTime = Date.now() + timeMs;
    this.timeRemaining = undefined;
  }
}

export { Timer as default };
//# sourceMappingURL=timer.js.map
