mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 19:01:47 +08:00
批量更新数据
This commit is contained in:
@@ -18,26 +18,8 @@ setTimeout(cancelFn, cancelTimeMs)
|
||||
<strong>Output:</strong> [{"time": 20, "returned": 10}]
|
||||
<strong>Explanation:</strong>
|
||||
const cancelTimeMs = 50;
|
||||
const result = [];
|
||||
|
||||
const fn = (x) => x * 5;
|
||||
|
||||
const start = performance.now();
|
||||
|
||||
const log = (...argsArr) => {
|
||||
const diff = Math.floor(performance.now() - start);
|
||||
result.push({"time": diff, "returned": fn(...argsArr)});
|
||||
}
|
||||
|
||||
const cancel = cancellable(log, [2], 20);
|
||||
|
||||
const maxT = Math.max(t, 50);
|
||||
|
||||
setTimeout(cancel, cancelTimeMs);
|
||||
|
||||
setTimeout(() => {
|
||||
console.log(result); // [{"time":20,"returned":10}]
|
||||
}, maxT + 15);
|
||||
const cancelFn = cancellable((x) => x * 5, [2], 20);
|
||||
setTimeout(cancelFn, cancelTimeMs);
|
||||
|
||||
The cancellation was scheduled to occur after a delay of cancelTimeMs (50ms), which happened after the execution of fn(2) at 20ms.
|
||||
</pre>
|
||||
@@ -49,6 +31,9 @@ The cancellation was scheduled to occur after a delay of cancelTimeMs (50ms), wh
|
||||
<strong>Output:</strong> []
|
||||
<strong>Explanation:</strong>
|
||||
const cancelTimeMs = 50;
|
||||
const cancelFn = cancellable((x) => x**2, [2], 100);
|
||||
setTimeout(cancelFn, cancelTimeMs);
|
||||
|
||||
The cancellation was scheduled to occur after a delay of cancelTimeMs (50ms), which happened before the execution of fn(2) at 100ms, resulting in fn(2) never being called.
|
||||
</pre>
|
||||
|
||||
@@ -59,6 +44,9 @@ The cancellation was scheduled to occur after a delay of cancelTimeMs (50ms), wh
|
||||
<strong>Output:</strong> [{"time": 30, "returned": 8}]
|
||||
<strong>Explanation:
|
||||
</strong>const cancelTimeMs = 100;
|
||||
const cancelFn = cancellable((x1, x2) => x1 * x2, [2,4], 30);
|
||||
setTimeout(cancelFn, cancelTimeMs);
|
||||
|
||||
The cancellation was scheduled to occur after a delay of cancelTimeMs (100ms), which happened after the execution of fn(2,4) at 30ms.
|
||||
</pre>
|
||||
|
||||
|
Reference in New Issue
Block a user