Added queue manager to properly fix the race condition bug and reset the changes I made in other commit
							parent
							
								
									b2f456031f
								
							
						
					
					
						commit
						fac8e72861
					
				@ -0,0 +1,28 @@
 | 
			
		||||
/* eslint-disable more/no-then */
 | 
			
		||||
 | 
			
		||||
// eslint-disable-next-line func-names
 | 
			
		||||
(function() {
 | 
			
		||||
  'use strict'
 | 
			
		||||
 | 
			
		||||
  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;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  window.JobQueue = JobQueue;
 | 
			
		||||
})();
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue