Why zlib.deflate(buf, callback) is async?

懵懂的女人 提交于 2020-01-15 15:39:18

问题


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)?

Doc: http://nodejs.org/api/zlib.html#zlib_zlib_deflate_buf_callback


回答1:


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).



来源:https://stackoverflow.com/questions/25220266/why-zlib-deflatebuf-callback-is-async

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!