lock icon indicating copy to clipboard operation
lock copied to clipboard

Locked timeout

Open bstanescu opened this issue 5 years ago • 3 comments

Spinlock with a twist (pun intended 😉)

Problem: I needed to throw an exception if the lock is already taken, but only after a given timeout.

Proposed solution The spinlock already has its own timeout (eg: 5 seconds). With this new option: lockedTimeout you can now specify a timeout while lock is already taken. (eg: 3 seconds). The process will try to acquire the lock for 3 seconds then throw an exception if it doesn't succeed.

If we specify a lockedTimeout of 0, the exception will be thrown immediately after the first lock acquire attempt.

This (with a lockedTimeout of zero) also addresses: https://github.com/php-lock/lock/issues/21#issuecomment-394963109

bstanescu avatar Oct 07 '19 09:10 bstanescu

Thanks. So you want to have a different timeout for acquiring the lock and the maximum lock execution, correct?

I think we should name the two locks then $acquisitionTimeout and $executionTimeout.

willemstuursma avatar Jul 28 '20 19:07 willemstuursma

Could you update all the files to change the naming, I'll have a better look in the coming days.

willemstuursma avatar Jul 28 '20 19:07 willemstuursma

this PR seems pretty interesting, is it still alive? Long time without any update on it...

pablomoreno61 avatar Mar 01 '21 16:03 pablomoreno61