Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternate release API seems broken #27

Closed
jlherren opened this issue Nov 27, 2020 · 1 comment
Closed

Alternate release API seems broken #27

jlherren opened this issue Nov 27, 2020 · 1 comment

Comments

@jlherren
Copy link

Hi, I really like this small library so far. My impression is that the following code should work properly:

let Mutex = require('async-mutex').Mutex;
let mutex = new Mutex();

async function doWork(id) {
    await mutex.acquire();
    try {
        console.log('Doing work', id);
    }
    finally {
        mutex.release();
    }
}

async function doEverything() {
    await Promise.all([
        doWork(1),
        doWork(2),
        doWork(3),
        doWork(4),
    ]);

    console.log('All done');
}

doEverything();

Expected output ("Doing work" lines not necessarily in that order):

Doing work 1
Doing work 2
Doing work 3
Doing work 4
All done

Actual output:

Doing work 1
Doing work 2

This only happens when using the alternate release API as described in the README. If I use the returned release function it works fine. I'm running this on node v12.19.1 on linux. But initially I experienced this issue in a web application (babel + webpack).

@DirtyHairy
Copy link
Owner

Thanks for the report. That was a nasty bug, fixed in v0.2.6 (and don't ask what happened to v0.2.5 😛 ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants