DirtyHairy / async-mutex

A mutex for synchronizing async workflows in Javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional acquire timeout?

cristianoccazinsp opened this issue · comments

It would be good to also provide a timeout argument to acquire. If the mutex is not acquired in that time, reject the promise.

I'd personally prefer not to have this feature added, mutexes are simple locking primitives and IMO they should not try to be something else..

If it were to be added I'd prefer a different class implementation for each type of locking mechanism.

If it were to be added I'd prefer a different class implementation for each type of locking mechanism.

That's why I haven't done anything on this issue yet: I don't want to add a timeout to the Mutex class itself. However, I am open to adding a wrapper class that provides this functionality to the package.

I just released version 0.2.1. The library now provides a withTimeout decorator that adds timeout behavior to both the Mutex and the newSemaphore. Check out the readme for more documentation.

Loved the approach!