add module for waiting
It isn't recommended tho
This commit is contained in:
		
							parent
							
								
									78fd39ca65
								
							
						
					
					
						commit
						fe2c59920d
					
				
					 1 changed files with 18 additions and 0 deletions
				
			
		
							
								
								
									
										18
									
								
								scripts/utils/wait.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								scripts/utils/wait.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,18 @@ | ||||||
|  | /* | ||||||
|  | Wait until a condition is met. It isn't recommended since you're better off using the callback on the function itself, but it's still here just in case.  | ||||||
|  | 
 | ||||||
|  | @param {Function} watch the condition to watch for | ||||||
|  | @param {Object} options the options | ||||||
|  | @return {Promise} the callback | ||||||
|  | */ | ||||||
|  | const wait = (watch, options) => { | ||||||
|  | 	return new Promise((resolve, reject) => { | ||||||
|  | 		(watch) | ||||||
|  | 			? resolve() | ||||||
|  | 			: setTimeout(() => { | ||||||
|  | 				wait(watch, options).then(resolve).catch(reject); | ||||||
|  | 			}, (((options && (typeof options).includes(`obj`)) ? options[`time`] : false) ? Math.abs(parseInt(options[`time`])) : 100)); | ||||||
|  | 	}); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export default wait; | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue