123456789101112131415161718192021222324252627282930313233343536 |
- import { __awaiter } from "tslib";
- export function asyncWhile(checker, callback) {
- return __awaiter(this, void 0, void 0, function* () {
- let index = 0;
- const newCallback = () => __awaiter(this, void 0, void 0, function* () {
- const checkRes = yield checker(index);
- if (checkRes) {
- yield callback(index);
- index++;
- yield newCallback();
- }
- });
- return yield newCallback();
- });
- }
- export function asyncForEach(array, callback) {
- return __awaiter(this, void 0, void 0, function* () {
- let index = 0;
- const newCallback = () => __awaiter(this, void 0, void 0, function* () {
- const item = array[index];
- const res = yield callback(item, index);
- if (index < array.length - 1 && res !== false) {
- index++;
- yield newCallback();
- }
- });
- return yield newCallback();
- });
- }
- export function nextTick(time = 0) {
- return new Promise((resolve) => {
- setTimeout(() => {
- resolve(true);
- }, time);
- });
- }
|