We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 85032df commit 10d0f14Copy full SHA for 10d0f14
js/setTimeout-interval.js
@@ -0,0 +1,29 @@
1
+/*
2
+ * @Author: Chacha
3
+ * @Date: 2022-05-23 23:33:55
4
+ * @Last Modified by: Chacha
5
+ * @Last Modified time: 2022-05-23 23:34:16
6
+ */
7
+
8
+const simulateSetInterval = (func, timeout) => {
9
+ let timer = null;
10
11
+ const interval = () => {
12
+ timer = setTimeout(() => {
13
+ func();
14
+ interval();
15
+ }, timeout);
16
+ };
17
18
19
20
+ return () => clearTimeout(timer);
21
+};
22
23
+const cancel = simulateSetInterval(() => {
24
+ console.log(1);
25
+}, 300);
26
27
+setTimeout(() => {
28
+ cancel();
29
+}, 1000);
0 commit comments