async
を使用して関数外のコードを停止できますawait
か? ただし、すべてのコードを停止したくはありません。実行するコードを制御したい。
次のような解決策があると思います。
var isAsyncRunning = false;
var currentPromise;
async function asyncFunc(){
isAsyncRunning = true;
//Do some code here
currentPromise = promise; //promise was defined inside the code
await promise;
promise.then(function(){
isAsyncRunning = false;
});
}
async function anotherFunction(){
if(!isAsyncRunning){
await currentPromise;
}
//Do some other code here
}
ただし、私は多くの機能を持っており、これをすべての機能に適用したくありません。
より良い解決策はありますか?そうでない場合、時間を短縮するためにできることはありますか?