mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	add time limit to frontend update
This commit is contained in:
		
							parent
							
								
									910bda860c
								
							
						
					
					
						commit
						d09b021487
					
				| @ -316,6 +316,24 @@ function dynamicRequire(moduleName) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| function timeLimit(cb, limitMs) { | ||||
|     return new Promise((res, rej) => { | ||||
|         let resolved = false; | ||||
| 
 | ||||
|         cb().then(() => { | ||||
|             resolved = true; | ||||
| 
 | ||||
|             res(); | ||||
|         }); | ||||
| 
 | ||||
|         setTimeout(() => { | ||||
|             if (!resolved) { | ||||
|                 rej('Process exceeded time limit ' + limitMs); | ||||
|             } | ||||
|         }, limitMs); | ||||
|     }); | ||||
| } | ||||
| 
 | ||||
| export default { | ||||
|     reloadApp, | ||||
|     parseDate, | ||||
| @ -355,5 +373,6 @@ export default { | ||||
|     normalizeShortcut, | ||||
|     copySelectionToClipboard, | ||||
|     isCKEditorInitialized, | ||||
|     dynamicRequire | ||||
|     dynamicRequire, | ||||
|     timeLimit | ||||
| }; | ||||
| @ -157,7 +157,7 @@ async function consumeSyncData() { | ||||
|         const nonProcessedSyncRows = allSyncRows.filter(sync => !processedSyncIds.has(sync.id)); | ||||
| 
 | ||||
|         try { | ||||
|             await processSyncRows(nonProcessedSyncRows); | ||||
|             await utils.timeLimit(async () => await processSyncRows(nonProcessedSyncRows), 5000); | ||||
|         } | ||||
|         catch (e) { | ||||
|             logError(`Encountered error ${e.message}: ${e.stack}, reloading frontend.`); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam