mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 15:11:31 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			23 lines
		
	
	
		
			502 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			502 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
/**
 | 
						|
 * Sync makes 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.
 | 
						|
 */
 | 
						|
 | 
						|
const Mutex = require('async-mutex').Mutex;
 | 
						|
const instance = new Mutex();
 | 
						|
 | 
						|
async function doExclusively(func) {
 | 
						|
    const releaseMutex = await instance.acquire();
 | 
						|
 | 
						|
    try {
 | 
						|
        await func();
 | 
						|
    }
 | 
						|
    finally {
 | 
						|
        releaseMutex();
 | 
						|
    }
 | 
						|
 | 
						|
}
 | 
						|
 | 
						|
module.exports = {
 | 
						|
    doExclusively
 | 
						|
}; |