Scheduler.ts 1.4 KB

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