UNPKG

sleepjs

Version:

Asynchronous sleep with better time functions and typescript bindings

23 lines (22 loc) 1.61 kB
"use strict"; 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 }); const sleep = (time) => __awaiter(void 0, void 0, void 0, function* () { return new Promise(resolve => setTimeout(() => resolve(time), time)); }); exports.sleep = sleep; exports.sleepMilliseconds = sleep; const sleepSeconds = (timeInSeconds) => __awaiter(void 0, void 0, void 0, function* () { return sleep(timeInSeconds * 1000); }); exports.sleepSeconds = sleepSeconds; const sleepMinutes = (timeInMinutes) => __awaiter(void 0, void 0, void 0, function* () { return sleepSeconds(timeInMinutes * 60); }); exports.sleepMinutes = sleepMinutes; const sleepHours = (timeInHours) => __awaiter(void 0, void 0, void 0, function* () { return sleepMinutes(timeInHours * 60); }); exports.sleepHours = sleepHours; const sleepDays = (timeInDays) => __awaiter(void 0, void 0, void 0, function* () { return sleepHours(timeInDays * 24); }); exports.sleepDays = sleepDays;