Search packages, repositories and app categories

Package detailsv0.2.0

isolate_agents

Agents are state that lives on a background isolate.

AndroidiOSmacOSWindowsLinux
30-day downloads
81
Likes
73
Pub points
160

Install package

flutter pub add isolate_agents

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

IsolateAgents is a Dart package that enables creating stateful agents running on background isolates, allowing safe, concurrent access to shared data without blocking the main thread. It provides a clean abstraction for managing isolate-based state with message passing, ideal for long-running or computationally intensive tasks. The package ensures thread safety by isolating state and communication through well-defined APIs. It's particularly useful in apps requiring persistent background processing, such as real-time data handling or complex calculations.

Use cases

  • Background data processing
  • Real-time analytics
  • Long-running computations
  • State management across isolates
  • Cross-isolate communication

Key features

  • Runs state on background isolates
  • Thread-safe state management
  • Message-passing API
  • Supports all major platforms
  • Simple agent lifecycle control

Suitable for

  • Apps needing heavy computation off main thread
  • Developers using isolates for concurrency
  • Projects requiring isolated state persistence
  • Teams building scalable background services
  • Flutter apps with real-time data needs

Considerations

  • Requires understanding of Dart isolates
  • Potential overhead from isolate creation
  • Limited debugging tools for isolates
  • Not suitable for simple state needs
  • Must handle serialization for inter-isolate messages

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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.

Categories

Source repository

Projects using this package

No data available yet.