moxystudio/node-proper-lockfile

Introduce synchronous signatures

gibson042 opened this issue · 7 comments

  • .lockSync(file, [options]) returns the release function or throws an err-code exception
  • .unlockSync(file, [options]) returns the release function or throws an err-code exception

As https://github.com/npm/lockfile#methods puts it:

Sync methods return the value/throw the error, others don't. Standard node fs stuff.

Oops closed by mistake

What I was saying is that we can easily do lockSync and unlockAsync by injecting a custom fs into the options with async functions that are actually sync. Doing it like that would be straightforward and would not introduce complexity.

I like that as an implementation principle, but there are two aspects necessary to keep it accordance with http://nodejs.org/api/fs.html (and https://github.com/npm/lockfile, for that matter): synchronous behavior, and a signature that returns/throws instead of accepting a callback. Dropping in a synchronous fs would address only the first.

Yes I agree. I would agree to add lockSync and unlockSync that return/throws like you expect, but internally it wraps options.fs with sync behavior like I suggested. Would you have time to do a PR?

@gibson042 can you take a look at 5726184 and ca15b92? It's working nicely.

Landed in 1.0.0.

Sorry I didn't get a chance to pick this up myself, but the changes look great. Thank you very much.