type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
type Fn = (...args: JSONValue[]) => void
function cancellable(fn: Fn, args: JSONValue[], t: number): Function {
let id = setTimeout(() => fn(...args), t);
// cancel delay
return () => clearTimeout(id);
};
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
type Fn = (...args: JSONValue[]) => void
function cancellable(fn: Fn, args: JSONValue[], t: number): Function {
// immediately called / setInterval 第一次立即执行
fn(...args);
// 💩 first call
let id = setInterval(() => fn(...args), t);
return () => clearInterval(id);
};
https://leetcode.com/studyplan/30-days-of-javascript/