gpui-async

Coordinate foreground UI updates with background tasks in GPUI apps.

62|1|Updated Feb 5, 2026
One-click install
npx skills add https://github.com/zerx-lab/rmx --skill gpui-async
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gpui-async
Source: https://github.com/zerx-lab/rmx/tree/main/.opencode/skills/gpui-async
Command: npx skills add https://github.com/zerx-lab/rmx --skill gpui-async

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

gpui-async coordinates foreground UI updates with long-running background tasks in GPUI apps.

Core Features & Use Cases

  • Foreground tasks: schedule UI updates using cx.spawn, ensuring updates occur on the UI thread.
  • Background tasks: offload CPU-heavy work with cx.background_spawn and chain results back to the UI via then.
  • Task lifecycle: automatic cancellation on drop and safe cleanup to prevent leaks.
  • Periodic tasks and coordination: support recurring work and synchronization between foreground and background work.

Quick Start

Foreground Task example: impl MyComponent { fn fetch_data(&mut self, cx: &mut Context<Self>) { let entity = cx.entity().downgrade(); cx.spawn(async move |cx| { // Runs on UI thread, can await and update entities let data = fetch_from_api().await; entity.update(cx, |state, cx| { state.data = Some(data); cx.notify(); }).ok(); }).detach(); } }

Background Task example: impl MyComponent { fn process_file(&mut self, cx: &mut Context<Self>) { let entity = cx.entity().downgrade(); cx.background_spawn(async move { let result = heavy_computation().await; result }).then(cx.spawn(move |result, cx| { entity.update(cx, |state, cx| { state.result = result; cx.notify(); }).ok(); })).detach(); } }

Frequently Asked Questions about gpui-async

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run background tasks in a GPUI app without blocking UI updates?

To run background tasks without blocking UI updates in a GPUI app, use cx.background_spawn to offload CPU-heavy work and chain results back to the UI thread via the then method. This keeps the interface responsive during asynchronous data fetching or media processing.

How does task cancellation work for async operations in GPUI?

Task cancellation for async operations in GPUI works automatically when the spawned task is dropped, ensuring safe cleanup and preventing memory leaks. This lifecycle management applies to both foreground UI updates and background work coordination.

What is the best way to update UI components from an async task in Rust?

The best way to update UI components from an async task in Rust is using cx.spawn to schedule foreground updates on the UI thread. You capture a downgraded entity, await your async operation, and call entity.update with cx.notify to refresh the component state.

Can I schedule periodic tasks and synchronize them with the UI thread in GPUI?

Yes, you can schedule periodic tasks and synchronize them with the UI thread in GPUI. The framework supports recurring background work and coordination between foreground and background operations, allowing periodic updates to safely refresh the UI state.

Does GPUI support foreground-only task execution for safe entity updates?

Yes, GPUI supports foreground-only task execution for safe entity updates using cx.spawn. This ensures that UI updates and entity state mutations occur strictly on the UI thread, preventing data races during asynchronous operations.