DirtyHairy/async-mutex

Mutex guarantees FIFO?

mannharleen opened this issue · 1 comments

Is it guaranteed that the mutex will be released in the same order that they are requested?

In the other words, the following should print 0 to 10 in that order.

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

for (let i=0; i<=10; i++){    
    let release = await mutex.acquire();
    console.log(`mutex acquired by i=${i}`)
    i === 0 ? setTimeout(release, 2000) : release()
}

Yes, locks are queued and resolved in the order in which they were were registered, FIFO style.