My async function and promise here:
Sort.bubbleSort = function () {
const timer = (ms) => new Promise((res) => setTimeout(res, ms));
async function sort() {
for(){
// i want to delay for every loop that's why I used async function and
//promise and timer here.
await timer(time);
}
}
// calling async function here
sort();
}
I called the bubblesort function on click element with id sort
document.getElementById("sort").addEventListener("click", Sort.bubbleSort);
So function started executing. I want to stop the function after click an element with id random-data.
Here I need solution:
document.getElementById("random-data").addEventListener("click", function () {
Sort.bubblesort().stop() // need to stop or pause
}
Here is live link. You can see and will understand easily what exactly I want and what's the issue.
Live Demo Link | Github Repository link