lib-curses
Version:
Simple node.js library for work with console
36 lines (35 loc) • 1.84 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loop = loop;
const wait_helper_1 = require("./wait.helper");
/**
* Executes a given asynchronous callback function in a loop until callback returns false.
* loop can include an optional pause between iterations.
*
* @param {function} callback - An asynchronous function that returns a boolean value.
* Loop will continue executing as long as this function returns true.
* @param {number} [milliseconds=0] - Amount of time to wait between each iteration of loop in milliseconds.
* If set to 0, no delay will be applied.
* @returns {Promise<void>} A promise that resolves when loop is exited.
*/
function loop(callback_1) {
return __awaiter(this, arguments, void 0, function* (callback, milliseconds = 0) {
let infinite = true;
// eslint-disable-next-line no-constant-condition
while (infinite) {
infinite = yield callback();
if (infinite && milliseconds) {
yield (0, wait_helper_1.wait)(milliseconds);
}
}
});
}
;