UNPKG

mihawk

Version:

A tiny & simple mock server tool, support json,js,cjs,ts(typescript).

24 lines (23 loc) 597 B
'use strict'; export async function sleep(time) { const aSleep = new Promise(res => setTimeout(res, time)); return await aSleep; } export async function timeoutPromise(prms, time) { return await Promise.race([ prms, new Promise(res => setTimeout(res, time)), ]); } export function throttleAsync(asyncFn, t = 0) { let lastCall = null; return async function (...args) { const n = Date.now(); if (lastCall == null || n - lastCall >= t) { lastCall = n; await asyncFn(...args); } else { } }; }