Why is there such a sequence in the console:
const crypto = require('crypto');
const https = require('https');
const fs = require('fs');
const startDate = Date.now();
const invokeHttpRequest = () => {
https.request('https://www.google.com', res => {
res.on('data', () => {});
res.on('end', () => {
console.log('HTTP returns data', Date.now() - startDate)
});
})
.end();
}
const invokeHash = () => {
crypto.pbkdf2('test', 'test2', 100000, 512, 'sha512' , () => {
console.log('crypto:', Date.now() - startDate);
});
}
invokeHttpRequest();
invokeHash();
invokeHash();
invokeHash();
invokeHash();
fs.readFile('index.js', 'utf-8', () => {
console.log('FS:', Date.now() - startDate);
});
I want to know how the loop works and why is there such a sequence in the console:
- HTTP returns data
- crypto
- FS
- crypto
- crypto
- crypto
Why exactly did FS skip crypto and take the second thread and not the last one