UNPKG

molstar

Version:

A comprehensive macromolecular library.

53 lines 2.34 kB
"use strict"; /** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ Object.defineProperty(exports, "__esModule", { value: true }); exports.chunkedSubtask = void 0; var tslib_1 = require("tslib"); var now_1 = require("../../mol-util/now"); function chunkedSubtask(ctx, initialChunk, state, f, update) { return (0, tslib_1.__awaiter)(this, void 0, void 0, function () { var chunkSize, globalProcessed, globalTime, start, lastSize, currentTime, delta; return (0, tslib_1.__generator)(this, function (_a) { switch (_a.label) { case 0: chunkSize = Math.max(initialChunk, 0); globalProcessed = 0, globalTime = 0; if (ctx.isSynchronous) { f(Number.MAX_SAFE_INTEGER, state); return [2 /*return*/, state]; } start = (0, now_1.now)(); lastSize = 0, currentTime = 0; _a.label = 1; case 1: if (!((lastSize = f(chunkSize, state)) > 0)) return [3 /*break*/, 4]; globalProcessed += lastSize; delta = (0, now_1.now)() - start; currentTime += delta; globalTime += delta; if (!ctx.shouldUpdate) return [3 /*break*/, 3]; return [4 /*yield*/, update(ctx, state, globalProcessed)]; case 2: _a.sent(); chunkSize = Math.round(currentTime * globalProcessed / globalTime) + 1; start = (0, now_1.now)(); currentTime = 0; _a.label = 3; case 3: return [3 /*break*/, 1]; case 4: if (!ctx.shouldUpdate) return [3 /*break*/, 6]; return [4 /*yield*/, update(ctx, state, globalProcessed)]; case 5: _a.sent(); _a.label = 6; case 6: return [2 /*return*/, state]; } }); }); } exports.chunkedSubtask = chunkedSubtask; //# sourceMappingURL=chunked.js.map