Tuesday, 13 February, 2018 UTC


Summary

  • The fetch API started out as a target for criticism because of lack of timeout and request cancelation.
  • I’ve recently been thinking about shimming in a fetch timeout and found a good fetch / timeout script here.
  • I’ve slightly modified it to prevent the  call’s  and  callbacks from carrying out their tasks because I believe the timeout should be handled by the shim’s Promise: – – Wrapping this code in a function called , whereby you pass in a timeout and fetch URL/settings would work well; since…
  • Many would argue that the timeout should come from the server but we all know us front-end devs don’t always have control over both sides of a request.
  • If you’re looking for a fetch request timeout snippet, here you go!
The fetch API started out as a target for criticism because of lack of timeout and request cancelation.  While those criticisms could be argued as fair or not, you can’t deny that the fetch API has been pretty awesome.  As we’ve always done, if a feature is missing, we can always shim it in.
@palashv2: JavaScript fetch with Timeout: #react #reactjs #angularjs #ui #100DaysOfCode #javascript…
The fetch API started out as a target for criticism because of lack of timeout and request cancelation.  While those criticisms could be argued as fair or not, you can’t deny that the fetch API has been pretty awesome.  As we’ve always done, if a feature is missing, we can always shim it in.
 callbacks from carrying out their tasks because I believe the timeout should be handled by the shim’s Promise:
, whereby you pass in a timeout and fetch URL/settings would work well; since people like to use fetch in a variety of ways, I’ve chosen not to create a generalized function and instead am just providing the basic logic.
Many would argue that the timeout should come from the server but we all know us front-end devs don’t always have control over both sides of a request.  If you’re looking for a fetch request timeout snippet, here you go!
The core problem with fetch when it comes to cancelation or timeout is baked into the underlying interface: Promises. Stateful, eager Promises just don’t model cancelation very well because the concept of a chain-able future value and potential side-effects of calling for and having that future value resolve/error are too tightly coupled.
Newer apis seem to be adopting Promises as their model for async requests a bit too glibly, I think, not really understanding this structural problem. Modeling timeouts as errors might make sense in a lot…
JavaScript fetch with Timeout