Timers in Nodejs


Timers in Nodejs
Set Timer function
setImmediate()
setTimeout()
setInterval()
-------------
Clear timer functions
clearImmediate()
clearTimeout()
clearInterval()
-------------
①Timer setInterval()

//
setInterval(callback, delay[, ...args])

・callback: <function>: Call function.
・delay : <number> : time loop.
・[...args] : function parameter.

//
let a = setInterval(function () {
    console.log('repeat !!!')
    //
    console.log(arguments)
}, 1000, 'parameter1', 'parameter2')
//setInterval return a obejct
console.log(typeof a)
②Timer setTimeout()
//
setTimeout(callback, wait[, ...args])
・callback: <function> Call function.
・wait: <number> time wait to call function.
・[...args] : Function callback parameters.

setTimeout(function (){
    console.log('run !')
}, 2000)

③Timer setImmediate()
//
setImmediate(callback, [, ...args])

・callback: <function> Call function.
・[...args] : Function callback parameters.
//
setImmediate(function() {
    console.log('1')
})

setImmediate(function() {
    console.log('2')
    setImmediate(function() {
        console.log('3')
    })
})

Không có nhận xét nào

Được tạo bởi Blogger.