Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

mutexify

let fs = require('fs/promises')
let mutexify = require('mutexify/promise')

async function asyncProcessWithMutexify() {
	try {
		let lock = await mutexify()

		let isRelease = await lock()
		fs.readFile('index1.txt').then((data) => {
			console.log('asyncProcessWithMutexify - ' + data.toString())
			isRelease()
		})

		isRelease = await lock()
		fs.readFile('index2.txt').then((data) => {
			console.log('asyncProcessWithMutexify - ' + data.toString())
			isRelease()
		})

		isRelease = await lock()
		fs.readFile('index3.txt').then((data) => {
			console.log('asyncProcessWithMutexify - ' + data.toString())
			isRelease()
		})
	} catch (e) {
		console.error(e)
	}
}

async function asyncProcessWithoutMutexify() {
	try {
		fs.readFile('index1.txt').then((data) => {
			console.log('asyncProcessWithoutMutexify - ' + data.toString())
		})

		fs.readFile('index2.txt').then((data) => {
			console.log('asyncProcessWithoutMutexify - ' + data.toString())
		})

		fs.readFile('index3.txt').then((data) => {
			console.log('asyncProcessWithoutMutexify - ' + data.toString())
		})
	} catch (e) {
		console.error(e)
	}
}

setInterval(async () => {
	await asyncProcessWithMutexify()
	await asyncProcessWithoutMutexify()
}, 2000)
Comment

PREVIOUS NEXT
Code Example
Javascript :: adding to an array in js 
Javascript :: Render JOSN in frontend 
Javascript :: js generate pnh 
Javascript :: new Date() how can i ue 
Javascript :: reduce dot notations to javascript array 
Javascript :: in node.js with express how to remove the query string 
Javascript :: express and jade, ignore render errors 
Javascript :: style dropdown react native picker 
Javascript :: jquery call service 
Javascript :: Triggering An Event Programmatically With JavaScript 
Javascript :: jquery event element in viewport 
Javascript :: laravel sending email to outlook link not working 
Javascript :: chat v2 msg and time good 
Javascript :: Saving dependencies in your node package.json syntax 
Javascript :: angular error handling 
Javascript :: puppeteer create folder 
Javascript :: Declaring A Internal Method Of A Class 
Javascript :: javascript how to random set rgb colors 
Javascript :: how do i block or restrict special characters from input fields with jquery 
Javascript :: checkbox null value javascript 
Javascript :: regex specific number of characters 
Javascript :: console.log(number++); console.log(++number); console.log(number); 
Javascript :: js beutify node.js 
Javascript :: Backbone Notes Miscellaneous 
Javascript :: remove T from datetime in js 
Javascript :: computed properties in react 
Javascript :: how to receive form data in node js 
Javascript :: js 1 second sleep 
Javascript :: javascript every function 
Javascript :: comment field react 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =