搜索插件、代码仓与 APP 分类

插件详情v0.2.0

isolate_agents

代理是驻留在后台隔离区中的状态。

AndroidiOSmacOSWindowsLinux
近 30 天下载
81
喜欢数
73
Pub 分数
160

安装插件

flutter pub add isolate_agents

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

IsolateAgents 是一个 Dart 包,可创建在后台 isolate 中运行的有状态代理,允许安全地并发访问共享数据,而不会阻塞主线程。它通过消息传递提供了一种简洁的抽象来管理基于 isolate 的状态,非常适合长时间运行或计算密集型任务。该包通过使用定义明确的 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.

所属分类

源码仓库

使用此插件的项目

暂无相关数据。