USAGE:
const asyncManager = require("asyncwriteprotect");
var fileWriter = new asyncManager();
var fpath = "./test.txt";
fileWriter.writeFile(fpath, "test1", function(r){
console.log(r);
});
fileWriter.writeFile(fpath, "test2", function(r){
console.log(r);
});
fileWriter.writeFile(fpath, "test3", function(r){
console.log(r);
});
fileWriter.writeFile(fpath, "test4", function(r){
console.log(r);
});
fileWriter.writeFile(fpath, "test5", function(r){
console.log(r);
});
fileWriter.writeFile(fpath, "test6", function(r){
console.log(r);
});
You can run these commands without worry of data corruption. The engine will queue up the async commands behind the scenes, so the writes will still run in a sync order. However, the backend is still async and doesn't pause while one is writing, so your code won't hang like calling all in a sync order.