From 67301f7b11f71225a6375c318d0d12f07f7d11d0 Mon Sep 17 00:00:00 2001 From: John Yani <361985+Vanuan@users.noreply.github.com> Date: Wed, 24 Jun 2026 04:11:54 +0300 Subject: [PATCH] Replace tokio sleep with background executor timer The documentation examples in skills/gpui/references/async.md contain incorrect async patterns that would panic at runtime. The correct pattern is to use GPUI's `cx.background_executor().timer()` instead of tokio's sleep functions. --- skills/gpui/references/async.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/skills/gpui/references/async.md b/skills/gpui/references/async.md index c55bf9f8e6..f25bf7c915 100644 --- a/skills/gpui/references/async.md +++ b/skills/gpui/references/async.md @@ -97,7 +97,8 @@ impl MyView { let _task = cx.spawn(async move |this, cx: &mut AsyncApp| { // Task automatically cancelled when dropped loop { - tokio::time::sleep(Duration::from_secs(1)).await; + cx.background_executor().timer(Duration::from_secs(1)).await; + this.update(cx, |state, cx| { state.tick(); cx.notify(); @@ -145,7 +146,8 @@ cx.background_spawn(async move { ```rust cx.spawn(async move |this, cx: &mut AsyncApp| { loop { - tokio::time::sleep(Duration::from_secs(5)).await; + cx.background_executor().timer(Duration::from_secs(5)).await; + this.update(cx, |state, cx| { state.tick(); cx.notify();