-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsynchronus.js
More file actions
50 lines (43 loc) · 1.12 KB
/
synchronus.js
File metadata and controls
50 lines (43 loc) · 1.12 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// let a=10;
// let b=20;
// let result=a+b;
// console.log(result);
function task1(){
console.log("Task1 started..");
//Between its starting and ending task let us assume
//the task is going to take some time. this will
//execute in fraction of seconds but,
//If i were to artificially induce some delay then the
//easiest way to do is in the below:
let start =Date.now();
//whatever is the current time of my machine now, i want to fetch it.
let delay=5000;
let end=start+delay;
console.log("Task1 executing...");
while(Date.now()<=end){
}
console.log("Task1 completed");
}
task1();
function task2(){
console.log("Task2 started..");
let start =Date.now();
let delay=3000;
let end=start+delay;
console.log("Task2 executing...");
while(Date.now()<=end){
}
console.log("Task2 completed");
}
task2();
function task3(){
console.log("Task3 started");
let start=Date.now();
let delay=2000;
console.log("Task3 executing...");
let end=start+delay;
while(start<=end){
}
console.log("Task3 completed");
}
task3();