dynamodb-lock-client
dynamodb-lock-client copied to clipboard
Feature Request: Support for Promises
Hello, This is a very nice lock client and I was looking to make use of it in a project that I was working on. However, because the APIs provided here are callback-based, integration has not been as clean as I would have loved it to be.
The Javascript Promise API is pretty mature enough especially for asynchronous programming and it enables developers to write cleaner, more readable code.
Would it be possible to provide a Promise based API for client.acquireLock
and lock.release
So that rather than doing something like as demonstrated in the README:
client.acquireLock("lock-key", (error, lock) =>
{
if (error)
{
return console.error(error)
}
console.log(`acquired fail open lock with fencing token ${lock.fencingToken}`);
lock.on("error", error => console.error("failed to heartbeat!"));
// do stuff.
lock.release(error => error ? console.error(error) : console.log("released fail open lock"));
}
);
developers can do something like:
try {
const lock = await client.acquireLock("lock-key");
console.log(`acquired fail open lock with fencing token ${lock.fencingToken}`);
lock.on("error", error => console.error("failed to heartbeat!"));
// do stuff.
await lock.release();
);
} catch (error) {
return console.error(error)
}
For my personal project, I have written a wrapper around the client to implement this behavior but I thought it'd be super useful to others as well.
Thank you.