牛逼的一道题

const EventEmitter = require('events');
const { readFileSync} = require('fs');
const myEvent = new EventEmitter

myEvent.on('event',()=>{
    console.log('01-event emit')
})

const sleep = s => {
    let time1 = Date.now();
    while(Date.now() - time1 < s){}
    console.log(`02-end sleep ${s}ms`)
}

setImmediate(()=>console.log('03-setImmediate'))

setTimeout(() => {
    console.log('04-setTimeout')
}, 1000);

process.nextTick(()=> console.log('05-nextTick'))

myEvent.emit('event')
new Promise(resolve => {
    console.log('06-new Promise')
    resolve()
}).then(()=>{
    console.log('07-Promise.then')
})

sleep(2000)

setTimeout(()=>{
    console.log('08-timeout 1000ms after sleep 2000ms')
},1000)

let syncFile = readFileSync('./package.json','utf8')
console.log('09-read sync files')

setTimeout(() => {
    console.log('10-timeout 0ms after sleep 2000ms')
}, 0);

你可能感兴趣的:(牛逼的一道题)