-
Notifications
You must be signed in to change notification settings - Fork 73
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
Add distributed locking capability #5
Conversation
src/errors.ts
Outdated
export class EtcdLockFailedError extends Error { | ||
constructor(message: string) { | ||
super(message); | ||
Object.setPrototypeOf(this, EtcdLockFailedError.prototype); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yo, if you target es6, you don't need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I was still have some issues with the ts-node-based unit tests. I'll see if there's an option to get it to target ES6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usually it uses es6
by default (because it's your tsconfig)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't for some reason, but setting an env var worked
If you can wait until etcd-io/etcd#7444 is released, I'd recommend using that instead. |
Ah, neat, I wasn't aware that was a thing. I'll probably get this in and switch over to that at some point in the future -- should be possible to do without any breaking changes. |
Example:
See the code for some more details. I branch off a bit from what, say python-etcd3 does and opted to use a lease for lock management. This prevents the resources from being locked indefinitely if an event occurs that prevents the consumer from unlocking the resource when they're finished with it. The logic is that the set of events which would allow a lease to be lost mid-lock is a subset of the events which would prevent the lease from ever being unlocked.