npm / lockfile

A very polite lock file utility, which endeavors to not litter, and to wait patiently for others.
ISC License
260 stars 33 forks source link

Support Promise API #33

Open dominic-p opened 5 years ago

dominic-p commented 5 years ago

With Promises being available in Node for a while now, it would be great if this library could return Promises.

Side note: has anyone tried this with util.promsify? Does that work as expected?

aikar commented 5 years ago
const util = require("util");
const lfLock = util.promisify(lf.lock);
const lfUnlock = util.promisify(lf.unlock);
await lfLock('a', {retries: 60000, retryWait: 100});
await lfUnlock('a');

works fine.

dominic-p commented 5 years ago

Thanks for the confirmation. I have been using it with promisify as well. It would still be nice if Promises were supported natively in my opinion, but it's a huge deal since promisify works.

aikar commented 5 years ago

Considering the async API's do not have any special return value at this time, I believe it would be safe to add promise support as a non breaking change.

If callback is null, return a promise, else behave the way it currently does. Could potentially always return a promise even.