本文介绍了为什么zlib.deflate(buf,callback)是异步的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当接受输入缓冲区并且知道压缩是CPU绑定的任务时,是否需要提供回调?
When accepting an input buffer, and knowing compression is a CPU bound task, does it needs to offer a callback? Is it just there to follow common practice like callback(err, result)
?
文档: http://nodejs.org/api/zlib.html#zlib_zlib_deflate_buf_callback
推荐答案
压缩/解压缩是在单独的线程中执行的,而不是在主线程中执行的.这就是为什么线程完成工作时需要回调.
The compression/decompression is executed in a separate thread and not in the main thread. That is why a callback is needed for when the thread completes its work.
回调样式与整个节点和大多数第三方模块(错误优先)使用的通用签名相同.
The callback style is the same common signature used throughout node and most third-party modules (error first).
这篇关于为什么zlib.deflate(buf,callback)是异步的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!