You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			25 lines
		
	
	
		
			430 B
		
	
	
	
		
			JavaScript
		
	
			
		
		
	
	
			25 lines
		
	
	
		
			430 B
		
	
	
	
		
			JavaScript
		
	
/* eslint-disable more/no-then */
 | 
						|
class JobQueue {
 | 
						|
  constructor() {
 | 
						|
    this.pending = Promise.resolve();
 | 
						|
  }
 | 
						|
 | 
						|
  add(job) {
 | 
						|
    const previous = this.pending || Promise.resolve();
 | 
						|
    this.pending = previous.then(job, job);
 | 
						|
    const current = this.pending;
 | 
						|
 | 
						|
    current.then(() => {
 | 
						|
      if (this.pending === current) {
 | 
						|
        delete this.pending;
 | 
						|
      }
 | 
						|
    });
 | 
						|
 | 
						|
    return current;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
module.exports = {
 | 
						|
  JobQueue,
 | 
						|
};
 |