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

NodeJS #1

Open
ZhiyuanSun opened this issue Aug 23, 2018 · 3 comments
Open

NodeJS #1

ZhiyuanSun opened this issue Aug 23, 2018 · 3 comments

Comments

@ZhiyuanSun
Copy link
Owner

No description provided.

@ZhiyuanSun
Copy link
Owner Author

ZhiyuanSun commented Aug 23, 2018

NodeJS Eventloop

https://segmentfault.com/a/1190000012258592
kaola-fed/blog#234
https://blog.csdn.net/liwusen/article/details/79509288

Timer -> I/O callbacks -> idle, prepare-> poll -> check -> close callbacks


"execute" setTimeout setInterval callback as soon as possible [1,2147483647] ->

other system callbacks (except setImmediate()), not user callback ->

idle for internal use ->

  • has timer? check timer and run whenever poll is clean
  • no timer? Clean up poll queue synchronically.

DONE CLEANING POLLING QUEUE

  • setimmediate()? go!
  • not setimmediate()? wait for new event, node block ->

check, setimmediate callback ->

close callbacks

nextTick/Promise are in between of stages, has it's own queue, will clean up

5b3dcdaa3b0be

68747470733a2f2f692e6c6f6c692e6e65742f323031382f30372f30352f356233646365333436343765642e706e67

@ZhiyuanSun
Copy link
Owner Author

ZhiyuanSun commented Aug 23, 2018

Promise tips

https://zhuanlan.zhihu.com/p/25178630

  1. .then and .catch only accept callbacks, otherwise value penetration
  2. .catch looks like the second argument of .then, but .catch can catch the error from first callback in .then

@ZhiyuanSun
Copy link
Owner Author

Web browser Eventloop

while(true) {
    macroQueue.shift()
    microQueue.all() // DOM mutation (max 60Hz), Promise
}

68747470733a2f2f692e6c6f6c692e6e65742f323031382f30372f30352f356233646365333437383062612e706e67

@ZhiyuanSun ZhiyuanSun changed the title ReadingNotes NodeJS Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant