Search packages, repositories and app categories

Package detailsv3.2.1

computer

Easy to use pool of concurrent workers with compute() like API.

AndroidiOSmacOSWindowsLinux
30-day downloads
1.4K
Likes
63
Pub points
160

Install package

flutter pub add computer

Package Overview

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

The computer package provides a simple, efficient pool of concurrent workers in Dart, offering a compute() API similar to Flutter's built-in compute function. It enables running CPU-intensive tasks off the main isolate, improving app responsiveness. Designed for ease of use, it abstracts away complex concurrency management while supporting multiple platforms including Android, iOS, macOS, Windows, and Linux. Ideal for background processing such as data parsing, image manipulation, or heavy computations.

Use cases

  • Running CPU-heavy operations in the background
  • Processing large datasets without blocking the UI
  • Performing image or file transformations
  • Executing long-running mathematical calculations
  • Improving app performance during intensive tasks

Key features

  • Simple compute() API
  • Cross-platform support
  • Automatic worker pool management
  • Lightweight and easy to integrate
  • Built-in error handling and retries

Suitable for

  • Developers needing background computation
  • Apps with intensive data processing
  • Projects requiring responsive UIs during heavy workloads
  • Teams wanting a drop-in alternative to Flutter's compute
  • Applications targeting multiple desktop and mobile platforms

Considerations

  • Not suitable for I/O-bound tasks
  • Limited customization of worker behavior
  • May consume more memory with many concurrent tasks
  • Best used for CPU-intensive rather than network operations
  • Requires careful handling of large data transfers between isolates

Original README

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

Computer

Computer is a lightweight library for concurrent computations, which provides Flutter's compute like API.

Features

  • Easy to use API
  • No overhead on creating & releasing isolates for each task. Workers initialized on start and ready to solve your tasks
  • Strictly defined number of workers

Note

Computer.shared() is a singleton, use Computer.create() to create new instances

How to use

Computer provides just 3 methods

turnOn()

Before using the Computer you need to turnOn it. This will create workers and initialize them. Then you may use compute() method.

final computer = Computer.create(); //Or Computer.shared()

await computer.turnOn(
  workersCount: 4, // optional, default 2
  verbose: false, // optional, default false
);
compute()

compute will execute your function inside one of the workers. Function may be async. The callback argument must be a top-level or static method of a class.

final result = await computer.compute(
  fib,
  param: 45, // optional
);
turnOff()

If you don't need workers anymore, you can turnOff the Computer. It will destroy workers.

await computer.turnOff();
Errors

ComputerError the parent error for all errors/exceptions in this package

class ComputerError implements Exception {
  final String message;
}

RemoteExecutionError shows up when something goes wrong in task

class RemoteExecutionError extends ComputerError {
  final Capability taskCapability;
}

CancelExecutionError shows up when turnOff is called but task is processing

class CancelExecutionError extends ComputerError {
  final Capability taskCapability;
}

Categories

Source repository

Projects using this package