Abort ecmascript7 async function
问题 Is there a way to cancel a ES7 async function? In this example, on click, I want to abort async function call before calling new. async function draw(){ for(;;){ drawRandomRectOnCanvas(); await sleep(100); } } function sleep(t){ return new Promise(cb=>setTimeout(cb,t)); } let asyncCall; window.addEventListener('click', function(){ if(asyncCall) asyncCall.abort(); // this dont works clearCanvas(); asyncCall = draw(); }); 回答1: There's nothing built in to JavaScript yet, but you could easily