-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
40 lines (36 loc) · 907 Bytes
/
main.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
import redisClient from "./utils/redis";
import dbClient from "./utils/db";
// (async () => {
// console.log(redisClient.isAlive());
// console.log(await redisClient.get("myKey"));
// await redisClient.set("myKey", 12, 5);
// console.log(await redisClient.get("myKey"));
// setTimeout(async () => {
// console.log(await redisClient.get("myKey"));
// }, 1000 * 10);
// })();
const waitConnection = () => {
return new Promise((resolve, reject) => {
let i = 0;
const repeatFct = async () => {
await setTimeout(() => {
i += 1;
if (i >= 10) {
reject();
} else if (!dbClient.isAlive()) {
repeatFct();
} else {
resolve();
}
}, 1000);
};
repeatFct();
});
};
(async () => {
console.log(dbClient.isAlive());
await waitConnection();
console.log(dbClient.isAlive());
console.log(await dbClient.nbUsers());
console.log(await dbClient.nbFiles());
})();