How does single-threaded JS implement multiple interactions at the same time
Answer: Simulate multi-threading with "rotary time slices" (segments that perform multiple tasks in turn in a short period of time)
Method to realize:
- Existing task 1, task 2
- Split task 1 and task 2
- Randomly arrange these task fragments to form a queue
- Send the task fragments to the JS engine in this queue order
- The JS engine executes these task fragments in turn
阅读 606
饼干陪你一起玩前端
爱思考,爱分享
1.5k 声望
176 粉丝
0 条评论
得票最新