Search⌘ K
AI Features

Exercise: A Tamper-Free Queue

Explore how to build a tamper-free Queue class in Node.js that exposes only one public dequeue method returning a Promise. Learn how the enqueue function asynchronously adds elements and unblocks dequeue Promises, and see how an HTTP server can interact with the queue for message processing.

Problem statement

Create a Queue class that has only one dequeue() named publicly accessible method. Such a method returns Promise that resolves with a new element extracted from an internal queue data structure. If the queue is empty, then Promise will resolve when a new item is added. The Queue class must also have a revealing constructor that provides a function called enqueue() to the executor that pushes a new element to the end of the ...