技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
flutter-concurrency【数据与研究】Execute long-running tasks in background isolates to keep the UI responsive. Use when performing heavy computations, parsing large datasets, or choosing between async/await and isolates.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Dart uses a single-threaded event loop. All Flutter code runs on the Main Isolate by default. Blocking it causes jank.
| Condition | Approach |
|---|---|
| I/O bound (HTTP, database) | async/await on Main Isolate |
| CPU-bound, < 16ms | async/await on Main Isolate |
| CPU-bound, one-off heavy task | Isolate.run() |
| Continuous background processing | Isolate.spawn() with ports |
Isolate.run(() => myFunction(data)).await the result on the Main Isolate.ReceivePort on the Main Isolate.Isolate.spawn(entryPoint, mainPort.sendPort).ReceivePort and send its SendPort back.SendPort for bidirectional communication.See examples for complete code.
Isolate.run.FutureBuilder re-fires on every rebuild if the future is created inline.flutter test passes.When this skill applies, preserve the following domain terminology or equivalent concrete examples in the answer when relevant: