-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path6-series.js
More file actions
47 lines (37 loc) · 1.02 KB
/
6-series.js
File metadata and controls
47 lines (37 loc) · 1.02 KB
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
'use strict';
// Emulate Asynchronous calls
const pause = () =>
new Promise((resolve) =>
setTimeout(resolve, Math.floor(Math.random() * 1000)),
);
// Asynchronous functions
const readConfig = async (name) => {
await pause();
console.log('(1) config loaded');
return { name };
};
const doQuery = async (statement) => {
await pause();
console.log('(2) SQL query executed: ' + statement);
return [{ name: 'Kiev' }, { name: 'Roma' }];
};
const httpGet = async (url) => {
await pause();
console.log('(3) Page retrieved: ' + url);
return '<html>Some archaic web here</html>';
};
const readFile = async (path) => {
await pause();
console.log('(4) Readme file loaded: ' + path);
return 'file content';
};
// Usage
const main = async () => {
const config = await readConfig('myConfig');
const res = await doQuery('select * from cities');
const json = await httpGet('http://kpi.ua');
const file = await readFile('README.md');
console.log('Done');
console.dir({ config, res, json, file });
};
main();