| 
									
										
										
										
											2020-10-30 15:34:04 -05:00
										 |  |  | // Copyright 2020 Signal Messenger, LLC
 | 
					
						
							|  |  |  | // SPDX-License-Identifier: AGPL-3.0-only
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-29 19:29:11 -04:00
										 |  |  | import PQueue from 'p-queue'; | 
					
						
							|  |  |  | import createTaskWithTimeout from '../textsecure/TaskWithTimeout'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function createJobQueue(label: string) { | 
					
						
							|  |  |  |   const jobQueue = new PQueue({ concurrency: 1 }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return (job: () => Promise<void>, id = '') => { | 
					
						
							|  |  |  |     const taskWithTimeout = createTaskWithTimeout(job, `${label} ${id}`); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return jobQueue.add(taskWithTimeout); | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export const storageJobQueue = createJobQueue('storageService'); |