In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
What is the role of FixedQueue in nodejs 14.0.0? for this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
FixedQueue is used to implement nextTick. There's not much code.
'use strict'
Const {Array,} = primordials
/ / Currently optimal queue size, tested on V8 6.0-6.6. Must be power of two.const kSize = 2048th Const kMask = kSize-1
Const FixedCircularBuffer = class FixedCircularBuffer {constructor () {this.bottom = 0; this.top = 0; this.list = new Array (kSize); this.next = null;}
IsEmpty () {return this.top = this.bottom;} / / to determine the loop isFull () {return ((this.top + 1) & kMask) = this.bottom;}
Push (data) {this.list [this.top] = data; this.top = (this.top + 1) & kMask;} / / remove an element, update the location shift () {const nextItem = this.list [this.bottom]; / / there are no elements, and there is no need to update the location if (nextItem = = undefined) return null; this.list [this.bottom] = undefined This.bottom = (this.bottom + 1) & kMask; return nextItem;}}
Module.exports = class FixedQueue {constructor () {this.head = this.tail = new FixedCircularBuffer ();}
IsEmpty () {return this.head.isEmpty ();}
If push (data) {/ / is full, apply for a new one. Head points to the new one, and tail points to the beginning, that is, the oldest if (this.head.isFull ()) {/ / Head is full: Creates a new queue, sets the old queue's `next` to it, / / and sets it as the new main queue. This.head = this.head.next = new FixedCircularBuffer ();} this.head.push (data);}
Shift () {const tail = this.tail; const next = tail.shift (); / / after consuming a FixedCircularBuffer, the next if (tail.isEmpty () & & tail.next! = = null) {/ / If there is another queue, it forms the new tail. This.tail = tail.next;} return next;}}
The answer to the question about what is the role of FixedQueue in nodejs 14.0.0 is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.