6 ms·
You can use a async/await with fetch to force it to be synchronous.
by TedDoesntTalk 5y ago
You can use a async/await with fetch to force it to be synchronous.
- kevingadd 5y agoasync/await is not synchronous, it's promises under the hood
- TedDoesntTalk 5y agoBut from a programming standpoint, you are assured that the next induction Edie’s not execute until the response is received.
- kevingadd 5y agoFunctionally this is still very different from sync xhr. Changing from sync xhr to await+fetch will introduce new bugs into your application unless it was written carefully, because now code can run and interactions can happen during the fetch that would have been blocked by the sync xhr occupying the event loop. Promises are also specced so that their handlers don't run until the event loop completes a turn, which means that no matter what there is now an opportunity for queued callbacks to run before you actually process the response to your request, even if it hit in-memory cache.
- Jasper_ 5y agoI would really love a synchronous spinMicrotasks() API, but for obvious reasons it's likely never happening.