Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation clarification on extend() #26

Closed
bradvogel opened this issue Nov 14, 2016 · 2 comments
Closed

Documentation clarification on extend() #26

bradvogel opened this issue Nov 14, 2016 · 2 comments

Comments

@bradvogel
Copy link

bradvogel commented Nov 14, 2016

The documentation seems to imply that extend() will extend the current timeout by X ms. So I'd think this would extend the lock to 15sec:

redlock.lock('locks:account:322456', 5000, function(err, lock) {
  lock.extend(5000, function(err, lock){
    lock.extend(5000, function(err, lock){
      // 15 secs or 5 secs?
    });
  });
});

But extend() appears to only overwrite the ttl, so it's only 5sec in the above example. This should be clarified in the docs, or extend() should be renamed ttl() since it's just resetting the ttl to a new value.

@bradvogel bradvogel changed the title Extend documentation clarification Documentation clarification on extend() Nov 14, 2016
@mike-marcacci
Copy link
Owner

Hi @bradvogel - this is a really good point; I guess there are actually 3 possibilities that could be true given the ambiguity of the name "extend":

1. it could extend the lock to X ms from "now"
2. it could extend the lock to X ms from its current TTL
3. it could extend the lock by resetting its initial TTL to X

Currently, it behaves like option 1 above, although I could definitely see the utility of option 2. Just out of curiosity, do you have a use case that would favor option 2? Or is the lack of clarity your primary concern here?

@bradvogel
Copy link
Author

bradvogel commented Nov 16, 2016

Just lack of clarity. I can't think of a use case for #2.

What about renaming extend() to ttl() so it make it clearer that you're re-setting the ttl. extend() to me implies #2 above - it's extending the current value, as if you're extending a timer (as opposed to resetting it).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants