-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathset_timeout.js
More file actions
32 lines (23 loc) · 769 Bytes
/
set_timeout.js
File metadata and controls
32 lines (23 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Scheduling methods - Timers (setTimeout(), setInterval()) , Promises, setImmediate(), process.nextTick()
// priority of methods used for scheduling callbacks - https://prakhartripathi.hashnode.dev/decoding-nodejs-callback-priority
/*
setTimeout is asynchronous method
which executes a function after specified time,
only ONCE.
*/
const greet = () => {
console.log("I will appear second");
}
console.log("this will appear first")
setTimeout(greet,3000);
/* setTimeout function returns timerId
which is given as arguement to clearTimeout.
*/
let timerId = setTimeout(greet,6000);
clearTimeout(timerId)
console.log("timer is stopped")
/*
You generally use the clearTimeout()
method when you need to cancel the
setTimeout() method call before it happens.
*/