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

Feature Request: Support for Promises #34

Open
jleoirab opened this issue Feb 10, 2022 · 0 comments
Open

Feature Request: Support for Promises #34

jleoirab opened this issue Feb 10, 2022 · 0 comments

Comments

@jleoirab
Copy link

jleoirab commented Feb 10, 2022

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.

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

1 participant