public static function throttle($function, $wait, array $options = [])
    {
        $options += [
            'leading' => true,
        ]; // @codeCoverageIgnore

        $previous = 0;

        $callback = function () use ($function, $wait, &$previous) {
            $now = floor(microtime(true) * 1000); // convert float to integer

            if (($wait - ($now - $previous)) <= 0) {
                $args = func_get_args();
                call_user_func_array($function, $args);
                $previous = $now;
            }
        };

        if ($options['leading'] !== false) {
            $callback();
        }

        return $callback;
    }