Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[js] 31.JS 单线程还是多线程,如何显示异步操作 #200

Open
qiilee opened this issue Sep 30, 2019 · 0 comments
Open

[js] 31.JS 单线程还是多线程,如何显示异步操作 #200

qiilee opened this issue Sep 30, 2019 · 0 comments
Labels

Comments

@qiilee
Copy link
Member

qiilee commented Sep 30, 2019

答案:JS 本身是单线程的,他是依靠浏览器完成的异步操作。

解析:

具体步骤,

1、主线程 执行 js 中所有的代码。

2、主线程 在执行过程中发现了需要异步的任务任务后扔给浏览器(浏览器创建多个线程执行),并在  callback queque  中创建对应的回调函数(回调函数是一个对象,包含该函数是否执行完毕等)。

3、主线程 已经执行完毕所有同步代码。开始监听  callback queque 一旦 浏览器 中某个线程任务完成将会改变回调函数的状态。主线程查看到某个函数的状态为已完成,就会执行该函数。

js_003

@qiilee qiilee added the JS label Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant