# gpui: Add an abstraction for scheduling foreground work for idle periods, and implement it for the web \(\#61827\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/82aef44308540b576e4e51fb379efa71614e5c91)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 82aef44308540b576e4e51fb379efa71614e5c91

Requested commit: 82aef44308540b576e4e51fb379efa71614e5c91

Commit: 82aef44308540b576e4e51fb379efa71614e5c91

Tree: fddb93ae284bb17adcb37890e415bcae3463e14a

Author: Cole Miller

Committer: GitHub

## Message

```
gpui: Add an abstraction for scheduling foreground work for idle periods, and implement it for the web (#61827)

- Add `ForegroundExecutor::spawn_when_idle(timeout, future)`, which
schedules `future` to be polled on the main thread when the main thread
is idle, but tries to do so no later than `timeout` after the current
instant (with the same `timeout` being applied to subsequent polls of
the same future)
- Add `Platform::dispatch_on_main_thread_when_idle(runnable, timeout)`
as the basis for `spawn_when_idle`, with a default implementation that
ignores the timeout and delegates to `dispatch_on_main_thread(runnable,
Priority::Low)`
- Implement `dispatch_on_main_thread_when_idle` for the web platform
using
[`requestIdleCallback`](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback)

Release Notes:
- N/A
```

## Parents

- [06b6160d46ae8a9074cd367ed64f742b47beca64](https://git.cafe/gitcafe/zed/commit/06b6160d46ae8a9074cd367ed64f742b47beca64?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/82aef44308540b576e4e51fb379efa71614e5c91?format=markdown)
