DirtyHairy/async-mutex

TypeError: objMutex.waitForUnlock is not a function

Closed this issue · 3 comments

why waitForUnlock not found ?

let {Mutex} = require('async-mutex');

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function f(){
	const objMutex = new Mutex();

	let promise = objMutex.runExclusive( async () => {
		await sleep(5000);
	});

	await objMutex.waitForUnlock();
	console.log('mutex unlocked');
}

f().then(console.log).catch(console.error);
TypeError: objMutex.waitForUnlock is not a function
    at f (E:\src\arbitr-jsm\test\mutex-test.js:14:17)
    at Object.<anonymous> (E:\src\arbitr-jsm\test\mutex-test.js:18:1)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47

You example works for me. This looks like an issue with your node setup and / or version. What version of node are you using?

I'm sorry I had an outdated version - "_id": "async-mutex@0.2.6"
After updating the package to "version": "0.3.2" everything works.

Never mind 😏