是不是真正的异步,非阻塞的JavaScript不可能的? [英] Isn't truly asynchronous, non-blocking javascript impossible?

查看:121
本文介绍了是不是真正的异步,非阻塞的JavaScript不可能的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我失去了一些东西在这里?

So, am I missing something here?

全部的JavaScript在流行的现代浏览器引擎(如2011年)的 单线程

All javascript engines in popular modern browsers (as of 2011) are single-threaded.

这意味着虽然事件可以异步发生,他们仍然(在单文件)要执行排队。

This means while EVENTS can occur asynchronously, they are still queued (in "single-file") to be executed.

这意味着所有这些技术外部JavaScript加载到HTML页面,他们真的是只允许在下载可同步发生,下载的$ C $但是C的执行,总是发生酮(功能)的时间,在一次一个文件

This means that all these techniques to load external javascript into an HTML page, they are really only to allow the download to happen asynchronously, the execution of the downloaded code however, always happens one (function) at a time, one file at a time.

所以其他的秘诀是我见过的网站以分手并执行初始化使用的setTimeout code块,那将是虚假的,不正确的建议 - 定时器也是一个单一的文件队列,只是为了执行。随着setTimeout的你只是导致通过定时器的乱序执行,并允许在浏览器中的其他事件在队列中跳跃(即鼠标点击或按键preSS等) - 这本身可能是很好的有,但它肯定不是异步code执行。

So other "tips" I've seen on the web to breakup and execute initializing code blocks using setTimeout, that would be bogus, incorrect advice - the timer is also a single-file queue and executes only in order. With setTimeout you are just causing an out-of-order execution via the timer and allowing other events in the browser (ie. mouse clicks or keypress, etc.) to jump in the queue - that in itself might be good to have, but it's certainly not asynchronous code execution.

如果我是正确的,有一堆坏了,误会建议在那里说的太经常反复。

If I'm right, there's a bunch of bad, misunderstood advice out there that's too often repeated.

推荐答案

难道你不混乱不同步并发?这是真的没有任何的并发的浏览器JS环境(除了网络工作者,和任何浏览器不会在内部,如I / O和渲染),但异步性的只是意味着所有来电都被无阻塞,和控制流总是立即返回。

Aren't you confusing asynchronicity with concurrency? It's true there isn't any concurrency in the browser JS environment (aside from web workers, and anything the browser does internally, like I/O and rendering), but asynchronicity just means that all calls are non-blocking, and control flow always returns immediately.

您'堵'/'非阻塞的定义不明确无论是。阻塞函数调用的广泛-S $ P $垫意义在于,它不给调用者返回控制,直到所有的计算,I / O等已完成。这只字未提并发。

Your definitions of 'blocking'/'non-blocking' aren't clear either. The wide-spread meaning of a blocking function call is that it doesn't return control to the caller until all computation, I/O, etc. has completed. This says nothing about concurrency.

这篇关于是不是真正的异步,非阻塞的JavaScript不可能的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆