Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

consider fetch as a macroTask #432

Closed
hmdhk opened this issue Sep 9, 2016 · 5 comments · Fixed by #1075
Closed

consider fetch as a macroTask #432

hmdhk opened this issue Sep 9, 2016 · 5 comments · Fixed by #1075

Comments

@hmdhk
Copy link
Contributor

hmdhk commented Sep 9, 2016

currently fetch is not considered as a task, for some application this is necessary to keep track of all macroTasks

@vicb
Copy link
Contributor

vicb commented Sep 10, 2016

could you please expand on this ?

@hmdhk
Copy link
Contributor Author

hmdhk commented Sep 10, 2016

@vicb , The Fetch API provides an interface for fetching resources (including across the network) which is similar to XMLHttpRequest API. for example there is a macroTask with 'XMLHttpRequest.send' as source which provides a way to keep track of async tasks.
similarly there can be a 'fetch' macroTask for async fetching of resources. Although since the fetch API returns a promise, the 'fetch' macroTask should be scheduled as soon as then is called on that promise. On the other hand you could also consider all 'unresolved' promises as macroTasks, since they're executed sometime in the future and out of current execution cycle.

This would be useful for applications that are using fetch API.

Also, I'm already making a fix for this, but my approach is to patch fetch API and attach a property to the promise and in the promise.then patch look for this property and schedule a macroTask accordingly. Feedback is appreciated :)

I hope this makes sense, Let me know if you need more info.

@mhevery
Copy link
Contributor

mhevery commented Sep 11, 2016

Yes, fetch() should be a macroTask.

@blaugold
Copy link

Is this issue still being considered? My use case is the apollo-client and change detection in protractor tests. apollo-client uses fetch to make requests but protractor can not wait for those requests because only Promise.then is scheduled and only after the response has come back. I would need the patched fetch to schedule a microTask before the original fetch implementation is called.

@CaerusKaru
Copy link
Member

@blaugold This doesn't help for the original issue, but apollo-client v2 has moved to Angular HttpClient instead of fetch, hopefully that fixes your problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants