ide / await-lock

Mutex locks for async functions
MIT License
89 stars 12 forks source link

Is order of acquiring the lock guaranteed? #12

Closed samjross closed 4 years ago

samjross commented 4 years ago

This isn't an issue so much as a question, but I don't see another place to ask a question and I don't see an answer to this in the documentation.

If I have my lock object, const lock = new AwaitLock();, and I'm calling await lock.acquireAsync(); in various places in the code, will those promises that I get back from .acquireAsync() always resolve in the same order I called them?

ide commented 4 years ago

Yes, they will acquire the lock in order. However there are no tests for this behavior and I wouldn't consider it part of the API.

If you rely on multiple tasks happening in a precise order for a reason other than fair scheduling and avoiding starvation, that means there's a dependency between your tasks that is easier to see if it's explicit in the code rather than implicit in this library's queue state.