Scheduler.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module INSPECTOR {
  2. export class Scheduler {
  3. private static _instance: Scheduler;
  4. /** The number of the set interval */
  5. private _timer : number;
  6. /** Is this scheduler in pause ? */
  7. public pause : boolean = false;
  8. /** All properties are refreshed every 250ms */
  9. public static REFRESH_TIME : number = 250;
  10. /** The list of data to update */
  11. private _updatableProperties: Array<PropertyLine> = [];
  12. constructor () {
  13. this._timer = setInterval(this._update.bind(this), Scheduler.REFRESH_TIME);
  14. }
  15. public static getInstance() : Scheduler {
  16. if (!Scheduler._instance) {
  17. Scheduler._instance = new Scheduler();
  18. }
  19. return Scheduler._instance;
  20. }
  21. /** Add a property line to be updated every X ms */
  22. public add(prop:PropertyLine) {
  23. this._updatableProperties.push(prop);
  24. }
  25. /** Removes the given property from the list of properties to update */
  26. public remove(prop:PropertyLine) {
  27. let index = this._updatableProperties.indexOf(prop);
  28. if (index != -1) {
  29. this._updatableProperties.splice(index, 1);
  30. }
  31. }
  32. private _update() {
  33. // If not in pause, update
  34. if (!this.pause) {
  35. for (let prop of this._updatableProperties) {
  36. prop.update();
  37. }
  38. }
  39. }
  40. }
  41. }