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

Avoiding writeFile collisions? #20

Closed ralyodio closed 8 years ago

ralyodio commented 8 years ago

Is it possible with this module?

I have a lot of asynchronous tasks that all write JSON to the same file in parallel. I will often get a corrupted file because two functions write to the file at the same time.

Is there anyway to avoid this using lockfile?

isaacs commented 8 years ago

Yes! Create a lock file whose file name is deterministicly generated from the json file name. You may also like http://npm.in/write-file-atomic

ralyodio commented 8 years ago

Can you provide an example?

also that link doesn't go anywhere.