-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add AbortSignal support #2241
Comments
The merge with suggested changes |
Hi @fedyk , thanks for filing the issue! The complex flow example is interesting, and not something I think I've considered before. Can you give me an example of how you'd use that ability to limit a complex flow to one timeout value ? I.e. is this a specific issue that you are trying to shore up in your implementation? Also, the Node SDK has to support Node 12 and above. Is there a backfill for this for Node 12? Thanks! |
I am working on endpoint that has 30s limit before the being cancelled. On timeout, the request is repeated, so previous API calls need to be stopped. The endpoint calls multiple APIs over HTTP (including Stripe). The endpoint has one time "budget" to call all services. Its unknown how long each API call will take,
For node v12, EOL for node v12 is 2022-04-30. I'd consider of adding a deprecation warning and ask to upgrade the node.js version. |
Thanks for the additional info @fedyk ; unfortunately, retiring older versions of runtimes is more difficult than it would seem for us, because of our wide install base. We are going to revisit older platform support in the coming year though! That being said though, I don't think we can support a feature that only works as documented on certain supported platforms, so we may need to hold off on this PR until we can retire Node v12. I will confirm with my team, but in the mean time, you could wrap let globalSignal = null;
const fetchWithSignal = (
input: string | URL | globalThis.Request,
init?: RequestInit,
): Promise<Response> => {
if (!init) {
init = {};
}
return fetch(input, {
...init,
signal: globalSignal,
});
};
const StripeClient = new Stripe('API_KEY', {
httpClient: Stripe.createFetchHttpClient(fetchWithSignal),
});
...
globalSignal = AbortSignal.timeout(30_000);
const invoice1 = await stripe.invoices.retrieve("inv_1")
const invoice2 = await stripe.invoices.retrieve("inv_1")
const customer1 = await stripe.customers.retrieve(invoice1.customer_id)
const customer2 = await stripe.customers.retrieve(invoice2.customer_id) Would something like this work for you here? |
Thanks for suggestion, we will consider your solution 👍 |
Sounds good. I'll keep this issue open for now but please let me know if this works for you! |
We created our own Stripe API client. We used native .Thanks for the help anyway! |
Is your feature request related to a problem? Please describe.
Since v14, Node.js supports
AbortSignal
andAbortController
. Both APIs allows to control async requests.It allows the implementation of complex flows. For instance, you have 30 seconds to make multiple requests to API. With one
AbortSingnal.timeout()
you can easily control the timing of the request:Describe the solution you'd like
Underhoos, stripe-node uses native
fetch
orhttp.request
. Both methods already have built-in support forAbortSingal
. By adding an option for passingsignal
in Stripe API methods, developers can leverage the signals in Stripe API.Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: