-
Notifications
You must be signed in to change notification settings - Fork 1
/
fakeServer.js
39 lines (38 loc) · 981 Bytes
/
fakeServer.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
class Server{
constructor(){
this.data=[];
}
get(index) {
return new Promise((resolve,reject)=>{
if(index>=this.data.length){
reject(new Error("not found"));
}
setTimeout(()=>{
resolve(this.data[index])
},2000)
})
}
put(data){
return new Promise((resolve,reject)=>{
setTimeout(()=>{
this.data[this.data.length] = {
data,
timestamp:Date.now()
};
resolve(this.data[this.data.length-1]);
},2000)
})
}
delete(index){
return new Promise((resolve,reject)=>{
if(index>=this.data.length){
reject(new Error("not found"));
}
setTimeout(()=>{
this.data.splice(index,1);
resolve("done")
},2000)
})
}
}
module.exports={Server};