You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
So that rather than doing something like as demonstrated in the README:
client.acquireLock("lock-key",(error,lock)=>{if(error){returnconsole.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{constlock=awaitclient.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.awaitlock.release(););}catch(error){returnconsole.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.
The text was updated successfully, but these errors were encountered:
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
andlock.release
So that rather than doing something like as demonstrated in the README:
developers can do something like:
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.
The text was updated successfully, but these errors were encountered: