Skip to content

chore: Replace tokio sleep with background executor timer#2504

Merged
huacnlee merged 1 commit into
longbridge:mainfrom
Vanuan:patch-1
Jun 24, 2026
Merged

chore: Replace tokio sleep with background executor timer#2504
huacnlee merged 1 commit into
longbridge:mainfrom
Vanuan:patch-1

Conversation

@Vanuan

@Vanuan Vanuan commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Fix Async Patterns in GPUI Documentation

Description

This PR fixes the async spawn examples in skills/gpui/references/async.md that contained incorrect patterns leading to runtime panics. The examples were using tokio's sleep functions (tokio::time::sleep) within GPUI's async context, which is incorrect. The correct pattern is to use GPUI's built-in timer functionality via cx.background_executor().timer().

Problem Solved:

  • Removed dependency on tokio for sleep functionality in GPUI async examples

Benefits:

  • Example will run without panics
  • Demonstrates the correct GPUI async pattern

Screenshot

Before After
[Runtime panic on async spawn] [Successfully runs and updates UI]

Break Changes

None. This is purely a documentation fix that corrects the example code.


Correct Async Pattern Example:

- // ❌ Incorrect: Uses tokio sleep and wrong spawn signature
- cx.spawn(...{
-     tokio::time::sleep(std::time::Duration::from_secs(2)).await;
-     cx.update(|cx| {
...
-     }).ok();
- });

+ // ✅ Correct: Uses GPUI's timer and proper spawn signature
+ cx.spawn(async move |this, cx| {
+     cx.background_executor()
+         .timer(std::time::Duration::from_secs(2))
+         .await;
+     
+     this.update(cx, |this, cx| {
...
+     }).ok();
+ });

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.
@huacnlee huacnlee changed the title Replace tokio sleep with background executor timer chore: Replace tokio sleep with background executor timer Jun 24, 2026
@huacnlee huacnlee merged commit e2fcc41 into longbridge:main Jun 24, 2026
3 checks passed
@huacnlee

Copy link
Copy Markdown
Member

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants