mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 21:19:01 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			22 lines
		
	
	
		
			502 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			502 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
/**
 | 
						|
 * Sync process can make data intermittently inconsistent. Processes which require strong data consistency
 | 
						|
 * (like consistency checks) can use this mutex to make sure sync isn't currently running.
 | 
						|
 */
 | 
						|
 | 
						|
import { Mutex } from "async-mutex";
 | 
						|
const instance = new Mutex();
 | 
						|
 | 
						|
async function doExclusively<T>(func: () => T) {
 | 
						|
    const releaseMutex = await instance.acquire();
 | 
						|
 | 
						|
    try {
 | 
						|
        return await func();
 | 
						|
    } finally {
 | 
						|
        releaseMutex();
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
export default {
 | 
						|
    doExclusively
 | 
						|
};
 |