How can I stop async function on click event javascript?

Solution for How can I stop async function on click event javascript?
is Given Below:

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

Something like this?

const Sort = {
  bubbleSort() {
    const timer = (ms) => new Promise((res) => setTimeout(res, ms));

    async function sort(self) {
      for (let i = 0; i <= 100; i++) {
        if (self.abort) {
          self.abort = false;
          return;
        }
        console.log(i);
        await timer(1000);
      }
    }

    sort(this);
  },

  bubbleSortStop() {
    this.abort = true;
  }
};

document.getElementById("sort")
  .addEventListener("click", Sort.bubbleSort.bind(Sort));

document.getElementById("random-data")
  .addEventListener("click", Sort.bubbleSortStop.bind(Sort));
<button id="sort">sort</button>

<button id="random-data">stop</button>