0👍
You may be able to use a generator to accomplish something similar to what you want. An example is below:
function* fetchData() {
let abort = false;
yield (async() => {
fetchSomeData().then((data) => {
if (abort) {
console.log("aborting")
return;
}
console.log("proceeding")
doStuff();
})
})();
yield abort = true;
}
const sequence = fetchData();
function openDialog() {
// This will fire the first yield in the generator, calling your async function
sequence.next()
}
function closeDialog() {
// This will fire the second yield in the generator, setting your flag
sequence.next()
}
This could allow you to encapsulate your ‘abort’ flag into a context that you could use to bail out, or do whatever else it is you need to do. Hope that’s helpful.
- [Vuejs]-Using vue-socket.io-extended, emit with vuex problem
- [Vuejs]-How can I verify token google recaptcha 3 on adonis js?
Source:stackexchange.com