setImmediate() and setTimeout()
来源:互联网 发布:淘宝评价和销量被删除 编辑:程序博客网 时间:2024/06/06 02:04
setImmediate method
Syntax
var retVal = window.setImmediate(handler, arguments);Standards information
- Efficient Script Yielding
Parameters
- handler [in]
Type: any
The function to be called.
- arguments [in, optional]
Type: any
Arguments to be passed to the function.
Return value
Type: IntegerA handle to the request.
Remarks
JavaScript operations run in the same thread as events, display updates, and other additional tasks. As a result, extended JavaScript operations (such as functions containing many lines of code) prevent additional tasks from being handled. In turn, this makes an application appear to be unresponsive because events (such as onclick or onkeypress) are not handled and the screen is not updated until the extended operation completes.
The setImmediate method schedules the function specified in the handler parameterto run after the current script block completes.If additional actions are pending when the current script block completes, they are processed before the handler function is called. This effectively creates a yield between the current script block and the handler function.
If you break extended operations into separate functions, you can use setImmediate to call each function in sequence. When you do this, setImmediate allows additional tasks to complete before calling each function in the sequence. In turn, this enables the application to respond to user input and to handle additional tasks in a predictable and responsive fashion.
For more information, see the setImmediate TestDrive demo.
Note
Some developers use setTimeout (or setInterval) to create events that accomplish similar results; however, there are subtle, but important differences between the two techniques.
The setTimeout method is restricted to 250 requests per second on most systems. This means that setTimeout(0, handler)
waits roughly 4ms before executing, even if no additional actions are pending. In contrast, setImmediate yields between each request, no matter how many requests are waiting to processed. If no additional actions are pending, setImmediate calls the handler function immediately.
- setImmediate() and setTimeout()
- setImmediate and process.nextTick
- setTimeout,setInterval,process.nextTick,setImmediate in Nodejs
- 细说setTimeout/setImmediate/process.nextTick的区别
- 细说setTimeout/setImmediate/process.nextTick的区别
- setTimeout和setImmediate以及process.nextTick的区别
- node异步API setTimeout,setInterval,process.nextTick,setImmediate详解
- Node.js中nextTick、setTimeout、setImmediate的区别
- nextTick, setTimeout 以及 setImmediate 三者的执行顺序
- promise.then,process.nextTick, setTimeout 以及 setImmediate 的执行顺序
- js setTimeout and setInterval
- setTimeout and setInterval
- Javascript 调度: setTimeout and setInterval
- JavaScript Timers with setTimeout and setInterval
- Process.nextTick 和 setImmediate
- setTimeout
- setTimeout
- setTimeout( )
- 记录点滴30
- ios开发学习--绘图(Drawing)效果源码分享
- freeglut在wxWidgets下的安装和使用
- 变色龙配置文件功能介绍
- Ext JS 4.0在eclipse中使用spket插件设置自动提示的方法
- setImmediate() and setTimeout()
- 业务建模 之 业务序列图
- [libxml2]_[XML处理]_[使用libxml2的xpath特性修改xml文件内容]
- Jackson 高性能的JSON处理 ObjectMapper
- Promise.timeout()
- 第二十章 XML
- 求向量中每100个点的平均值
- 生成uImage
- Eclipse中如何查看Java自带函数的源代码?