DEV Community

Discussion on: How to Abort a Fetch Request in JavaScript using AbortController

Collapse
 
digitalbrainjs profile image
Dmitriy Mozgovoy • Edited

Or we can just use the cross-platform solution (Demo):

import cpFetch from "cp-fetch";

const promise1 = cpFetch("https://api.github.com/users/nas5w")
  .timeout(10000)
  .then((res) => res.json())
  .then(console.log, console.warn);

setTimeout(() => promise1.cancel(), 10);
Enter fullscreen mode Exit fullscreen mode