So I am not sure how to convert a function that I have that is built synchronously but uses asynchronous calls.
do_thing = () => {
var N = new Thing(); //sync
N.do_that(); // calls fs.readFile() and does some stuff with data :async
this.array.push(N); // sync but does not affect anything
this.save(); // calls fs.writeFile() but needs info from N that is not created yet as N.do_that() is not done
}
I am not sure how to make it so when N.do_that()
is done it then calls this.save()
. I do not want to use fs.readFileSync()
or fs.writeFileSync()
. I would like to know how to something like:
N.do_that().then( this.save() );