MaxTime.js 852 B

123456789101112131415161718192021222324
  1. var t = require;
  2. var e = module;
  3. var i = exports;
  4. Object.defineProperty(i, "__esModule", {value: !0});
  5. const s = t("constants"),
  6. o = t("Decorator");
  7. i.default = class extends o.default {
  8. constructor({maxTime: t, child: e = null} = {}) {
  9. if ((super({child: e, name: "MaxTime", title: "Max <maxTime>ms", properties: {maxTime: 0}}), !t))
  10. throw "maxTime parameter in MaxTime decorator is an obligatory parameter";
  11. this.maxTime = t;
  12. }
  13. open(t) {
  14. var e = new Date().getTime();
  15. t.blackboard.set("startTime", e, t.tree.id, this.id);
  16. }
  17. tick(t) {
  18. if (!this.child) return s.ERROR;
  19. var e = new Date().getTime(),
  20. i = t.blackboard.get("startTime", t.tree.id, this.id),
  21. t = this.child._execute(t);
  22. return e - i > this.maxTime ? s.FAILURE : t;
  23. }
  24. };