Skip to content
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

Make http requests cancelable #512

Closed
wants to merge 3 commits into from
Closed

Make http requests cancelable #512

wants to merge 3 commits into from

Conversation

serg-plusplus
Copy link

@serg-plusplus serg-plusplus commented Nov 22, 2020

Why?

Taquito has very heavy methods under the hood which make a lot of requests, such as Estimate or ReadViewLambda.
When using it in interfaces, there is often a case when the method needs to be canceled almost immediately.
So, the goal is the network optimization.

My vision of this story is that there is an RPCOptions argument with the signal property in all of Taquito's methods that use RPC queries under the hood.

Made for https://developer.mozilla.org/en-US/docs/Web/API/AbortController.

Example

const abortCtrl = new AbortController();

const reqPromise = httpBackend.createRequest({ url: "https://...", signal: abortCtrl.signal });

reqPromise
  .then(console.info)
  .catch(console.error);

setTimeout(() => {
  abortCtrl.abort();
}, 100);

Use AbortController in different environments

There are three main environments where your JavaScript code can run in:

  • Modern Browsers: You can use AbortController without problems because AbortController was created to work with the DOM by the WHATWG.
  • Node: If you want to use AbortController in Node, you can do it using an implementation of the WHATWG AbortController interface. You can use different npm packages to achieve this, for example, abort-controller or node-fetch.
  • Legacy Browsers: You need to use polyfills, for example, with Babel.

TODO

  • Your code builds cleanly without any errors or warnings
  • You have added unit tests
  • You have added integration tests (if relevant/appropriate)
  • All public methods or types have TypeDoc coverage with a complete description, and ideally an @example
  • You have added or updated corresponding documentation
  • If relevant, you have written a first draft summary describing the change for inclusion in Release Notes.

@ghost
Copy link

ghost commented Nov 22, 2020

Congratulations 🎉. DeepCode analyzed your code in 15.98 seconds and we found no issues. Enjoy a moment of no bugs ☀️.

👉 View analysis in DeepCode’s Dashboard | Configure the bot

@jevonearth
Copy link
Collaborator

Thanks for the @serh11p
We will schedule how to integrate this after we ship tzip16 and beacon v2 work. :) Really appreciate the PR illustrating the way.

@jevonearth jevonearth added this to the v8.1 milestone Mar 2, 2021
@Innkst Innkst modified the milestones: v8.1, v8.2, v8.3 Mar 23, 2021
@roxaneletourneau roxaneletourneau self-assigned this May 11, 2021
@Innkst Innkst modified the milestones: v9.1, v9.2 May 25, 2021
@roxaneletourneau
Copy link
Collaborator

This implementation would require changes in the high-level API. Here is an example where a custom HttpBackend class is used to be able to cancel all requests: #914.
I'm closing this for now; an implementation to cancel specific requests will be considered when designing the issue 432, which might require providing a new API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants