私は、同期でビルドされているが非同期呼び出しを使用している関数をどのように変換するのか分かりません。nodejs非同期機能する方法?
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
}
私はそれはとてもN.do_that()
が行われたときに、それは、その後this.save()
を呼び出すようにする方法を確認していません。私はfs.readFileSync()
またはfs.writeFileSync()
を使いたくありません。私は何かのようなものを知りたいです:
N.do_that().then(this.save());