ide / await-lock

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

Option to return immediately if lock is taken #3

Closed indeyets closed 5 years ago

indeyets commented 5 years ago

I have a workflow, which would benefit if it were possible to try to get the lock and fail immediately if it is taken by other greenlet.

Would you take a patch implementing this?

There are 2 ways to implement this:

  1. return Promise<bool> (true = success, false = failure)
  2. throw exception on failure, leave everything as-is on success
ide commented 5 years ago
indeyets commented 5 years ago

Do you want a customizable timeout?

I don't

Do you want to wait for one tick of the event loop to try and acquire the lock, or do you want to immediately acquire the lock synchronously?

No preference, actually. Both are fine for me

ide commented 5 years ago

Published tryAcquire in 1.2.0: https://github.com/ide/await-lock/releases. See the code for documentation, though it's pretty straightforward.