-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatingPromise.js
More file actions
40 lines (37 loc) · 934 Bytes
/
CreatingPromise.js
File metadata and controls
40 lines (37 loc) · 934 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
33
34
35
36
37
38
39
40
const fakeRequest = (url) => {
return new Promise((resolve, reject) => {
const rand= Math.random();
setTimeout(() => {
if(rand<0.7){
resolve('YOUR FAKE DATA IS HERE');
}
reject('CONNECTION TIMEOUT');
}, 1000)
})
}
async function makeTwoRequest(){
try{
let data1= await fakeRequest('/page2');
let data2= await fakeRequest('/page2');
console.log(data1)
console.log(data2)
console.log("HELOO!!!!")
}
catch(e){
console.log("caught an error", "and the error is :",e);
}
}
makeTwoRequest()
// try{
// sadgg.log('asags')
// }catch(e){
// console.log("hhhhhhhhhhhhh",e)
// }
// fakeRequest('/dogs/1')
// .then((data)=>{
// console.log("DONE IW")
// console.log('data is: ', data)
// })
// .catch((err)=>{
// console.log('oh no!', err);
// })