groupon / gofer

A general purpose service client library for node.js
BSD 3-Clause "New" or "Revised" License
82 stars 18 forks source link

feat: support AbortController signal #125

Closed aaarichter closed 3 years ago

aaarichter commented 3 years ago
const { fetch } = require('gofer');
const ac = new AbortController(); // Node 15+

ac.signal.addEventListener('abort', () => console.log('Aborted!'), { once: true });

await Promise.race([
  fetch('https://example.com', { signal: ac.signal }).text().catch(err => /*  err this will say it was aborted */),
  async () => { return '<html>'; }
]).finally(() => ac.abort());