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

Consider to add "resolveAtIdleTime" to RequestInit #821

Open
smaug---- opened this issue Oct 27, 2018 · 9 comments
Open

Consider to add "resolveAtIdleTime" to RequestInit #821

smaug---- opened this issue Oct 27, 2018 · 9 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api

Comments

@smaug----
Copy link

During TPAC there was discussion about having lower priority fetches. The idea was something more complicated, but perhaps we could actually start by just hinting when fetch()'s promise should be resolved.
Idle time could work reasonable well for many cases, though perhaps there would need to be also some max timeout to ensure it gets resolved at some point.

And since XHR is very commonly used, something similar could be added there too.

(Just recording this idea here, so that I don't forget it.)

@spanicker

@yoavweiss
Copy link
Collaborator

This seems related to other proposals on that front, most notably priority hints.

/cc @domfarolino @addyosmani

@domfarolino
Copy link
Member

Definitely seems related to PH agreed, though seems to cover a superset of the problems PH is geared toward (given that resolving in idle time could mean delaying resolution due to either network or main thread contention). I think the networking-priority portion of this would be best suited for Priority Hints though.

Did you have any specific cases in mind where this might be most helpful? Currently I’m looking for as many network-contention-heavy scenarios as I can where user-supplied priority hints may result in a perceivable win, so I’m open to hearing anything you may have in mind.

@annevk annevk added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api labels Oct 29, 2018
@smaug----
Copy link
Author

Priority hints is about the networking side. This is more about the stuff discussed TPAC about handling network responses at lower priority.

@yoavweiss
Copy link
Collaborator

yoavweiss commented Oct 29, 2018

Is there a reason we can't define a single API/developer-signal to implement both network priority and response handling?

@smaug----
Copy link
Author

Sure we can. As I said in the initial comment, I just filed the issue to record the idea somewhere before I forget.

@spanicker
Copy link

spanicker commented Oct 29, 2018

Is there a reason we can't define a single API/developer-signal to implement both network priority and response handling?

I cannot think of a reason to not tackle both the problems (other than scope), makes sense to consider both aspects. However the response handling priority is a bit different: it needs a way to pass a priority (that won't always necessarily be the same as fetch priority), that can potentially be updated (eg. something was fetched preemptively to prepare next screen, but now the user has explicitly requested it or vice versa).

Ability to specify priority for fetch promise resolution (and something for xhr) makes sense to me.
However I'd like to see better support for priorities than just "idle".
I'll think about this more and loop back with a proposal for priorities.
(I agree with Yoav that those same set of priorities should also be able to be hinted on the fetches themselves)

@yutakahirano
Copy link
Member

Just having a general function, say waitForIdle, looks simpler to me. We can use it with timeout fairly easily.

function wait(ms) { return new Promise(res => setTimeout(res, ms)); }
const timeout = wait(100);
const resp = await fetch(...);
await Promise.race([waitForIdle(), timeout]);

This actually executes tiny code when it's not idle, but I think we can bear with it.

@ken0x0a
Copy link

ken0x0a commented Mar 2, 2019

I guess Promise.race doesn't actually abort fetch ... Is it still working in background, isn't it?

@annevk
Copy link
Member

annevk commented Jan 30, 2021

See also #436.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest topic: api
Development

No branches or pull requests

7 participants