3 ms·
I think GP means that a synchronous blocking call in an async runtime would block and bring the executor (event loop) to a global halt. Think import { readF
by whilenot-dev 2y ago
I think GP means that a synchronous blocking call in an async runtime would block and bring the executor (event loop) to a global halt.
Think
import { readFileSync } from 'node:fs';
async function main() {
const data = readFileSync(
'/etc/machine-id',
{ encoding: 'utf-8' },
);
console.log(data);
}
await main();
VS
import { readFile } from 'node:fs';
async function main() {
const data = await new Promise((resolve, _reject) => {
readFile(
'/etc/machine-id',
{ encoding: 'utf-8' },
(_err, data) => {
resolve(data);
},
);
});
console.log(data);
}
await main();
(no error handling to bring the point better across).