-
Notifications
You must be signed in to change notification settings - Fork 0
/
callback.js
38 lines (32 loc) · 855 Bytes
/
callback.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
function login(username, password, callback) {
setTimeout(function () {
if (username === 'kernelnewbies' && password === '123456') {
callback(null, '8ef9e41db21905efdefd45241466f9b3')
} else {
callback(new Error('username or password error'), null)
}
}, 3000)
}
function fetchProfile(token, callback) {
setTimeout(function () {
if (token === '8ef9e41db21905efdefd45241466f9b3') {
callback(null, "{'name':'kernelnewbies','age':18}")
} else {
callback(new Error('token error'), null)
}
}, 3000)
}
login('kernelnewbies', '123456', function onLogin(error, token) {
if (error) {
console.log(error)
return
}
console.log(token)
fetchProfile(token, function onFetchProfile(error, profile) {
if (error) {
console.log(error)
return
}
console.log(profile)
})
})