-
Notifications
You must be signed in to change notification settings - Fork 0
/
database.js
53 lines (32 loc) · 1.12 KB
/
database.js
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
51
52
// Drawback of plain js
// Dependent request wont wait for the required data and finally is error (Callback dependency)
console.log("Service1 Started!")
fetchData = (email, password) => {
setTimeout( ()=>{
console.log("Server1 Data is fetched and is ready!")
return email
}, 3000) // Say time to fetch data form DB is 3secs
}
const user = fetchData("hello@gmail.com", "1234567890")
console.log("MailId is: ", user)
console.log("Service1 closed!\n\n\n")
// Instataneous thread execution without any delay
console.log("Service2 started!");
retrieveData = (mail, pass) => {
return mail
}
const cust = retrieveData("dbservices@gmail.com", "abcdefg")
console.log("MailId is: ", cust)
console.log("Service2 closed!\n\n\n")
// Solution to the error using call back
console.log('Server3 Started!')
const selectData = (mail, pass, callback) => {
console.log("Data request sent...")
setTimeout(() => {
callback("Mailid: " + mail)
}, 2000);
}
const data = selectData("qwerty@gmail.com", "123", ()=>{
console.log("qwerty@gmail.com")
})
console.log('Server3 Closed!');