mirror of
				https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
				synced 2025-10-31 01:55:29 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			18 lines
		
	
	
		
			496 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
		
			496 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import { isPromise } from './is-promise.js';
 | |
| export function maybeAsyncResult(getResult, resultHandler, errorHandler = (err) => {
 | |
|     throw err;
 | |
| }) {
 | |
|     try {
 | |
|         const result = isFunction(getResult) ? getResult() : getResult;
 | |
|         return isPromise(result)
 | |
|             ? result.then((result) => resultHandler(result))
 | |
|             : resultHandler(result);
 | |
|     }
 | |
|     catch (err) {
 | |
|         return errorHandler(err);
 | |
|     }
 | |
| }
 | |
| function isFunction(arg) {
 | |
|     return typeof arg === 'function';
 | |
| }
 | 
