MCPcopy
hub / github.com/BrainJS/brain.js / Thaw

Function Thaw

browser.js:26446–26492  ·  view source on GitHub ↗
(items)

Source from the content-addressed store, hash-verified

26444 }]);
26445
26446 function Thaw(items) {
26447 var _this = this;
26448
26449 var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
26450
26451 _classCallCheck(this, Thaw);
26452
26453 var _constructor$defaultS = _extends({}, this.constructor.defaultSettings, options),
26454 each = _constructor$defaultS.each,
26455 done = _constructor$defaultS.done;
26456
26457 this.items = items;
26458 this.i = 0;
26459 this.options = options;
26460 var tick = this.tick = function () {
26461 if (_this.i < 0) return;
26462
26463 _this.timeout = setTimeout(tick, 0);
26464
26465 if (thawing) return;
26466 var item = items[_this.i];
26467 if (_this.i >= items.length) {
26468 if (done !== null) {
26469 thawing = true;
26470 done(item, _this.i);
26471 thawing = false;
26472 }
26473
26474 _this.i = -1;
26475 clearTimeout(_this.timeout);
26476 return;
26477 }
26478 if (each !== null) {
26479 thawing = true;
26480 each(item, _this.i);
26481 thawing = false;
26482 } else if (item !== undefined) {
26483 item();
26484 }
26485 _this.i++;
26486 };
26487
26488 thaws.push(this);
26489 if (!options.delay) {
26490 tick();
26491 }
26492 }
26493
26494 /**
26495 * readies thaw to continue

Callers

nothing calls this directly

Calls 2

_classCallCheckFunction · 0.70
doneFunction · 0.70

Tested by

no test coverage detected