Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

gpui-async

/gpui-async

Obsługuje operacje asynchroniczne i zadania w tle w GPUI: spawn, asynchroniczne I/O, długie obliczenia i koordynacja aktualizacji interfejsu z pracą w tle.

Repozytorium
zqlz ↗
Licencja
GPL-3.0
Ostatnia zmiana repozytorium
17.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 17.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

GPL-3.0, otwarta.

Co robi i kiedy

Obsługuje operacje asynchroniczne i zadania w tle w GPUI: spawn, asynchroniczne I/O, długie obliczenia i koordynacja aktualizacji interfejsu z pracą w tle.

Oryginalny opis (EN)

Async operations and background tasks in GPUI. Use when working with async, spawn, background tasks, or concurrent operations. Essential for handling async I/O, long-running computations, and coordinating between foreground UI updates and background work.

Jak działa

  1. Overview
  2. Quick Start
  3. Core Patterns
  4. Common Pitfalls
  5. Reference Documentation
Sekcje z nagłówków SKILL.md, w oryginale · 172 linii, 447 słów
Podgląd SKILL.md
---
name: gpui-async
description: Async operations and background tasks in GPUI. Use when working with async, spawn, background tasks, or concurrent operations. Essential for handling async I/O, long-running computations, and coordinating between foreground UI updates and background work.
---

## Overview

GPUI provides integrated async runtime for foreground UI updates and background computation.

**Key Concepts:**
- **Foreground tasks**: UI thread, can update entities (`cx.spawn`)
- **Background tasks**: Worker threads, CPU-intensive work (`cx.background_spawn`)
- All entity updates happen on foreground thread

## Quick Start

### Foreground Tasks (UI Updates)

```rust
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 Tasks (Heavy Work)

```rust
impl MyComponent {
    fn process_file(&mut self, cx: &mut Context<Self>) {
        let entity = cx.entity().downgrade();

        cx.background_spawn(async move {
            // Runs on background thread, CPU-intensive
            let result = heavy_computation().await;
            result
        })
        .then(cx.spawn(move |result, cx| {
            // Back to foreground to update UI
            entity.update(cx, |state, cx| {
                state.result = result;
                cx.notify();
            }).ok();
        }))
        .detach();
    }
}
```

### Task Management

```rust
struct MyView {
    _task: Task<()>,  // Prefix with _ if stored but not accessed
}

impl MyView {
    fn new(cx: &mut Context<Self>) -> Self {
        let entity = cx.entity().downgrade();

        let _task = cx.spawn(async move |cx| {
            // Task automatically cancelled when dropped
            loop {
                tokio::time::sleep(Duration::from_secs(1)).await;
                entity.update(cx, |state, cx| {
                    state.tick();
                    cx.notify();
                }).ok();
            }
        });

        Self { _task }
    }
}
```

## Core Patterns

### 1. Async Data Fetching

```rust
cx.spawn(async move |cx| {
    let data = fetch_data().await?;
    entity.update(cx, |state, cx| {
        state.data = Some(data);
        cx.notify();
    })?;
    Ok::<_, anyhow::Error>(())
}).detach();
```

### 2. Background Computation + UI Update

```rust
cx.background_spawn(async move {
    heavy_work()
})
.then(cx.spawn(move |result, cx| {
    entity.update(cx, |state, cx| {
        state.result = result;
        cx.notify();
    }).ok();
}))
.detach();
```

### 3. Periodic Tasks

```rust
cx.spawn(async move |cx| {
    loop {
        tokio::time::sleep(Duration::from_secs(5)).await;
        // Update every 5 seconds
    }
}).detach();
```

### 4. Task Cancellation

Tasks are automatically cancelled when dropped. Store in struct to keep alive.

## Common Pitfalls

### ❌ Don't: Update entities from background tasks

```rust
// ❌ Wrong: Can't update entities from background thread
cx.background_spawn(async move {
    entity.update(cx, |state, cx| { // Compile error!
        state.data = data;
    });
});
```

### ✅ Do: Use foreground task or chain

```rust
// ✅ Correct: Chain with foreground task
cx.background_spawn(async move { data })
    .then(cx.spawn(move |data, cx| {
        entity.update(cx, |state, cx| {
            state.data = data;
            cx.notify();
        }).ok();
    }))
    .detach();
```

## Reference Documentation

### Complete Guides
- **API Reference**: See [api-reference.md](references/api-reference.md)
  - Task types, spawning methods, contexts
  - Executors, cancellation, error handling

- **Patterns**: See [patterns.md](references/patterns.md)
  - Data fetching, background processing
  - Polling, debouncing, parallel tasks
  - Pattern selection guide

- **Best Practices**: See [best-practices.md](references/best-practices.md)
  - Error handling, cancellation
  - Performance optimization, testing
  - Common pitfalls and solutions

Wersje

RepozytoriumWynikLicencja
Ta strona · samurmaykrr/zqlz100GPL-3.0
pinkpixel-dev/skills-collection-1100Apache-2.0

Migawka bazy z 13.11.2026 · wersja paczki e71c5feefa9f (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100gpui-test
    Prowadzi pisanie testów aplikacji GPUI: komponenty, operacje asynchroniczne i zachowanie interfejsu.
  • 100gpui-testing
    Testuje aplikacje i komponenty GPUI: pisanie testów, operacje asynchroniczne, symulacja wejścia użytkownika i debugowanie nieudanych testów.
  • 100gpui-entity
    Obsługuje zarządzanie encjami i stanem w GPUI: stan komponentów, koordynacja między komponentami, aktualizacje stanu z operacji asynchronicznych i wzorce reaktywne.
  • 100gpui-kit
    Pokazuje, jak budować aplikacje desktopowe w Rust z biblioteką GPUI Kit: komponenty, stan, motywy, akcje i zadania asynchroniczne.
  • 100gpui-code-quality
    Podaje dobre praktyki i wytyczne jakości kodu GPUI, przy refaktoryzacji, przeglądach i dbaniu o idiomy GPUI.
  • 95fastapi-async-patterns
    Opisuje wzorce asynchroniczne w FastAPI do budowy wydajnych API obsługujących współbieżne żądania i operacje async.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.