If you overwrite the same file using multiple instances simultaneously, an error occurs.
const { readFile } = require('fs/promises')
const writeJsonFile = require('write-json-file')
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
async function run() {
await wait(100)
const data = JSON.parse((await readFile('bar.json')).toString())
await writeJsonFile('foo.json', data)
}
async function main() {
while (true) {
await run()
}
}
main()
Open 3 instances of NodeJS and run the code simultaneously.
NodeJS: v16.17.0
write-json-file: v4.3.0
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too