-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy path1-sequential-callbacks.js
More file actions
41 lines (33 loc) · 973 Bytes
/
Copy path1-sequential-callbacks.js
File metadata and controls
41 lines (33 loc) · 973 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
41
'use strict';
// Sequential calls and sequential execution
// of 4 pseudo-asynchronous functions
const readConfig = (name, callback) => {
setTimeout(() => {
console.log(`(1) config loaded: ${name}`);
callback(null, { name });
}, 1000);
};
const doQuery = (statement, callback) => {
setTimeout(() => {
console.log(`(2) SQL query executed: ${statement}`);
callback(null, [{ name: 'Kiev' }, { name: 'Roma' }]);
}, 1000);
};
const httpGet = (url, callback) => {
setTimeout(() => {
console.log(`(3) Page retrieved: ${url}`);
callback(null, '<html>Some archaic web here</html>');
}, 1000);
};
const readFile = (path, callback) => {
setTimeout(() => {
console.log('(4) Readme file loaded');
callback(null, 'file content');
}, 1000);
};
console.log('start');
readConfig('myConfig', () => {});
doQuery('select * from cities', () => {});
httpGet('http://kpi.ua', () => {});
readFile('README.md', () => {});
console.log('end');

