Do JS use Non blocking I/O at OS level to support AJAX?

回眸只為那壹抹淺笑 提交于 2020-01-04 03:23:06

问题


If Javascript is a single threaded process and AJAX is asynchronous then how does it happen ? So at OS level ain't the JS engine making a Non-Blocking I/O call for Ajax ?


回答1:


Yes, the browser engine is making a non-blocking I/O call for Ajax (when you do a non-blocking ajax call).

There are any number of different ways the browser could implement the ajax networking. The only thing we know for sure is that the ajax i/o request isn't blocking the javascript thread. And, further every browser is free to implement it differently as long as they don't block the JS execution thread and any other threads needed to keep the browser functional during the ajax call.

Under the covers, inside the browser, it could be using a separate OS thread to run the ajax call in a blocking fashion on that thread, it could be using non-blocking i/o on a separate thread, it could be using non-blocking i/o on the javascript interpreter thread (probably unlikely, but possible). It could even be using a separate process to manage networking operations with IPC to communicate between them. Which it chooses is entirely up to the browser implementation as any of those methods will allow the javascript interpreter to keep running while the ajax networking happens asynchronously. It's also possible that different browsers have somewhat different implementations.

Chrome, for example uses a separate process for each browser window which other browsers do not.



来源:https://stackoverflow.com/questions/9998433/do-js-use-non-blocking-i-o-at-os-level-to-support-ajax

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