We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 07b10d9 commit c2a2fd4Copy full SHA for c2a2fd4
1 file changed
JavaScript/5-timeout.js
@@ -4,15 +4,14 @@
4
5
const timeout = (msec, f) => {
6
let timer = setTimeout(() => {
7
- if (timer) console.log('Function timedout');
+ if (timer) console.log('Function timed out');
8
timer = null;
9
}, msec);
10
return (...args) => {
11
- if (timer) {
12
- clearTimeout(timer);
13
- timer = null;
14
- return f(...args);
15
- }
+ if (!timer) return;
+ clearTimeout(timer);
+ timer = null;
+ return f(...args);
16
};
17
18
0 commit comments