搜尋套件、儲存庫與 APP 分類

套件詳情v0.2.0

isolate_agents

代理是位於背景隔離區中的狀態。

AndroidiOSmacOSWindowsLinux
近 30 天下載
81
喜歡數
73
Pub 分數
160

安裝套件

flutter pub add isolate_agents

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

IsolateAgents 是一個 Dart 套件,可建立在背景隔離執行緒中運行的狀態代理,允許安全地並發存取共用資料,而不會阻塞主執行緒。它透過訊息傳遞提供一種乾淨的抽象來管理基於隔離的狀態,非常適合長時間執行或計算密集型的工作。該套件透過明確定義的 API 隔離狀態與通訊,確保執行緒安全。在需要持續背景處理的應用中特別實用,例如即時資料處理或複雜運算。

適用情境

  • 背景資料處理
  • 即時分析
  • 長時間執行的計算
  • 跨隔離區的狀態管理
  • 跨隔離區通訊

主要特色

  • 在背景隔離區執行狀態
  • 執行緒安全的狀態管理
  • 訊息傳遞 API
  • 支援所有主要平台
  • 簡單的代理生命週期控制

適合對象

  • 需要在主執行緒之外進行大量計算的應用程式
  • 使用隔離區進行併發的開發者
  • 需要隔離狀態持久化的專案
  • 建構可擴展的後台服務
  • 需要即時資料的Flutter應用

使用建議

  • 需要理解 Dart isolates
  • 隔離建立帶來的潛在開銷
  • 用於隔離的除錯工具有限
  • 不適合簡單的狀態需求
  • 必須處理隔離間訊息的序列化

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Isolate Agents

Description

Isolate Agents adds a new class, Agent, which is a proper implementation of the Actor model for Dart. Where Isolates have no mechanism for communication, Agents do. It is inspired by Clojure's agents.

Example usage

import 'package:isolate_agents/isolate_agents.dart';

void main() async {
  Agent<int> agent = await Agent.create(() => 1);
  // The following add operation is executed in the Agent's isolate.
  agent.update((int x) => x + 1);
  assert(2 == await agent.exit());
}

Why?

After writing Dart code for a couple of years I realized I was writing the same code over and over again in order to be able to use Isolates. Isolates don't fully implement the Actor model so a handshake of SendPort and a protocol needs to be devised for each non-trivial usage of Isolates. Agents factor all that logic into a reusable package, eliminating the SendPort handshake and standardizing the protocol.

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。