question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve support for passing AbortSignal

See original GitHub issue

Three things I think could improve working with signals.

  1. I’m getting the following type error: Type 'AbortSignal' is missing the following properties from type 'AbortSignal': reason, throwIfAbortedts.

    While Masto uses AbortSignal types from node-fetch, my app uses AbortSignal type from lib.dom since the target is a browser (I also can’t pass Headers due to the same type conflict).

    FWIW I found https://www.npmjs.com/package/undici to have better API compatibility with the browser compared to node-fetch.

  2. Make it easier to set a signal for the session: login({ url, accessToken, signal }).

  3. Make it easier to set a signal for a specific request.

    This is not a common use case, I don’t think it’s worth adding that option to every API request, but some way of cloning the client with a different signal + access token.

Issue Analytics

  • State:open
  • Created 9 months ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
assafcommented, Dec 26, 2022

I’d rather prefer adding a second argument that specifies a RequestInit to every method from repositories.

I thought that would be too complicated, but I’d rather have an options argument on each request. That’s easier than dealing with login.

I don’t think it should be RequestInit though. RequestInit includes too many things that I expect the Masto API to ignore — HTTP method, request body, content type, etc. I think it should be a subset of properties (headers, signal, what else?)

In Node.js newer than 18, there’s fetch API in global so we use it by default.

Node 18 ships with undici (https://nodejs.org/en/blog/announcements/v18-release-announce/#fetch-experimental).

You may wonder why we don’t use types provided by lib-dom.

Not really. I only use lib-dom in code that runs in the browser/edge servers, and @types/node in code that runs on Node. The problem with node-fetch is that it’s incompatible with both.

would recommend you cast the value you provided for time being.

Another option is for the Masto API to use W3C types and then cast those to node-fetch behind the scenes as an implementation detail.

0reactions
neetcommented, Dec 27, 2022

I’m not saying you’re wrong. I determined that it was the comprehensive and the simplest way to cover use cases by the lowest maintenance cost because even if I restrict functionality by my decision I cannot handle one feature request after another! I hope you understand🙏

Read more comments on GitHub >

github_iconTop Results From Across the Web

AbortSignal - Web APIs - MDN Web Docs - Mozilla
The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a fetch request) and abort ......
Read more >
Support AbortSignal for aborting requests · Issue #3506 - GitHub
Allow passing an AbortSignal in. Listen to abort instead of doing .promise.then on the cancel token. Describe alternatives you've considered.
Read more >
Using AbortSignal in Node.js - NearForm
The awaitable timer API supports the ability to pass in an AbortSignal instance. When the AbortSignal is triggered, the timer is cleared and ......
Read more >
The complete guide to AbortController in Node.js
Introduction to AbortSignal; How to use AbortSignal to time out async ... You can pass an optional reason for aborting to the abort...
Read more >
Improving your applications with AbortController - YouTube
The Web Platform APIs introduced AbortController and AbortSignal to help solve this problem. They allow us to cancel asynchronous tasks in a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found