See https://github.com/whatwg/html/issues/617 for the Promise.delay
equivalent.
I am happy to specify this if we have any implementation interest. (And I agree it would be on Window
, or more likely WindowOrWorkerGlobalScope
, not on Promise
. Another reason is that certain host environments, like worklets, want to prevent clock-dependent behavior, so having this in the language would be bad.) It would also be abortable using AbortSignal
, per the above-linked thread.
For your Promise.timeout
, I suggest AbortSignal.timeout(2000)
, used like so:
fetch(url, { signal: AbortSignal.timeout(2000) })
(maybe AbortSignal.after
would be a reasonable name too.) For that, the next step would be filing an issue on https://github.com/whatwg/dom/issues and working toward implementer interest. This was previously discussed a bit in https://github.com/whatwg/fetch/issues/951#issuecomment-541369940. Again, I am happy to specify this if we have any implementation interest.