DEV Community

Aleksei Aleinikov
Aleksei Aleinikov

Posted on

🛑 The “Stop Button” for Async JavaScript in 2025

You kick off a fetch()...
Then something changes — new tab, new request, new file.
Don’t wait. Abort it.

Modern JS gives you AbortController — a tiny control switch for clean, cancellable async ops.

🔥 Use cases

  • 🎵 Skip song in playlist — abort previous audio stream.
  • 📊 Live dashboard — stop polling when tab closes.
  • 📁 Upload — drag a new file? Cancel the old one.
  • 🔄 SSE stream — pause feed when tab goes background.

💡 Best practices

  • Never reuse a controller after .abort()
  • Catch AbortError to avoid messy logs
  • Use per-request controllers for clarity

📍 Full guide with examples: https://javascript.plainenglish.io/the-asynchronous-stop-button-cancelling-operations-in-2025-830a4c213972

Top comments (0)