function timeout(callback, timeout) {
    let timer;
    const run = function () {
        if (timer) {
            clearTimeout(timer);
            timer = null;
            callback.apply(this, arguments);
        }
    };
    timer = setTimeout(run, timeout, new Error("timeout"));
    return run;
}
Return a callback with timeout

@param {function} callback
@param {number} timeout
@return {function}