const fs = require('fs');
fs.readFile('testFile1.txt', function (err, data) {
console.log('data read of testFile0.txt');
// 模擬CPU密集型任務
computing()
});
fs.readFile('testFile2.txt', function (err, data) {
console.log('data read of testFile1.txt');
});
// CPU密集型任務
functioncomputing() {
for (let i = 0; i < 10000; i++)//
{
for (let j = 0; j < 10000; j++) {
for (let k = 0; k < 100; k++) { }
}
}
}
// 輸出結果:
// 11:55:30 AM data read of testFile0.txt
// 11:55:56 AM data read of testFile1.txt
複製代碼