Skip to content

dev-ardi/responseq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AsyncQ

Async queue. This is a queue where you can post async requests and then get them one by one. It blocks until there is one promise available. This is first responded first out, rather than first requested, first out.

Example:

import ResponseQ from 'responseq';
async function getUsers(IDs: string[]) {
 const q = new ResponseQ(); // Create a new AsynQ instance
  for (const id of IDs) {
    q.push(async () => getUserFromDB(id)); // Push a function to the queue 
  }
  for (let i = 0; i < IDs.length; i++) {
    const user = await q.pop(); // Consume the output one by one
    frontend.drawUser(user);
  }
}