"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.throttle = void 0;
const lodash_1 = require("lodash");
const throttle = (fn, wait, option = {
    leading: true,
    trailing: false,
}) => {
    const throttled = lodash_1.throttle(async (...args) => {
        const AsyncFunction = (async () => { }).constructor;
        if (fn instanceof AsyncFunction) {
            await fn(...args);
        }
        else {
            fn(...args);
        }
        return Date.now();
    }, wait, option);
    let prevTs;
    let currTs;
    let isThrottled;
    const thunk = (...args) => {
        currTs = throttled(...args);
        isThrottled = prevTs === currTs;
        prevTs = currTs;
    };
    return {
        throttledFn: thunk,
        isThrottled: () => isThrottled,
    };
};
exports.throttle = throttle;
