Some people are going to think this is too trivial to look for modules or almost put it in a leftPad category perhaps, but there are so many things in npm I have a feeling these two requirements are covered and so am interested to see what other people have done.

I inherited this codebase that has this sort of long updating function with a number of steps. It has sort of a custom locking flag that is half-set-up to expire but doesn't actually have the expiration code. Anyway, the main thing is to prevent the update from happening while something else is happening. Except sometimes we know we definitely need to update as soon as possible, but not right in the middle of a current update. This stuff is not actually quite working.

So I am looking for one or two modules to do two things:

  1. a lock with an expiration that two different long-running functions (that call other functions with callbacks) can use to make sure they don't step on each other

  2. a simple module/function that says 'do this function now, or run it again after it finishes its current run'.

Or possibly something that handles both of those might actually make sense in this case, even though from my description it may not be obvious what they have to do with each other.

The expiration is if there is some case that I don't anticipate that causes the lock not to be removed, we don't want to be stuck forever.

  • What is npm? Please edit – user416 Sep 30 '16 at 10:28

This is what I decided I need to do: I created a really simple module now-or-again and am using the existing lock-lock with its maxPending feature instead of an expiration time.

The way I am using those two modules is identical to the examples in the READMEs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy