DirtyHairy / async-mutex

A mutex for synchronizing async workflows in Javascript
MIT License
1.14k stars 63 forks source link

TypeError: objMutex.waitForUnlock is not a function #58

Closed uranik777 closed 2 years ago

uranik777 commented 2 years ago

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
DirtyHairy commented 2 years ago

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

uranik777 commented 2 years ago

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.

DirtyHairy commented 2 years ago

Never mind 😏