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.
		
		
		
		
		
			
		
			
				
	
	
		
			29 lines
		
	
	
		
			535 B
		
	
	
	
		
			JavaScript
		
	
			
		
		
	
	
			29 lines
		
	
	
		
			535 B
		
	
	
	
		
			JavaScript
		
	
| /* 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;
 | |
| })();
 |