File size: 845 Bytes
dfe72e0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import pino from "pino";
const logger = pino();
/**
* Pause for a specified number of seconds.
* @param x Minimum number of seconds.
* @param y Maximum number of seconds (optional).
*/
export const sleep = (x: number, y?: number): Promise<void> => {
let timeout = x * 1000;
if (y !== undefined && y !== x) {
const min = Math.min(x, y);
const max = Math.max(x, y);
timeout = Math.floor(Math.random() * (max - min + 1) + min) * 1000;
}
// console.log(`Sleeping for ${timeout / 1000} seconds`);
logger.info(`Sleeping for ${timeout / 1000} seconds`);
return new Promise(resolve => setTimeout(resolve, timeout));
}
export const corsHeaders = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
} |