Skip to content
pubscout

thread

0.2.2, released 4 years ago by drafakiller.com

Type-safe isolated thread with event emitter for async communication

$ flutter pub add thread
Source repository

What it does

Provides a lightweight wrapper around Dart Isolates that uses a type‑safe EventEmitter to send and receive data. It supports starting, pausing, resuming, and stopping the isolate, as well as running single tasks via compute methods.

AI-written summary of version 0.2.2, based on the package's README and metadata. Report an inaccuracy

Use it when

  • Need to offload CPU‑heavy work to a background isolate
  • Require event‑driven communication between isolate and main thread
  • Want to pause or resume isolate execution
  • Need a simple API without external dependencies

Skip it when

  • Simple single‑threaded async work
  • When performance of starting/stopping isolates is critical
  • When you already use a more feature‑rich concurrency library

Strengths

  • Type‑safe event communication
  • Built‑in pause/resume and lifecycle control
  • Compute methods for one‑off tasks
  • No external code generation required

Weaknesses

  • Recent breaking changes in file structure and imports
  • Limited documentation on edge cases
  • Not widely adopted, community support is small

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
3

Add dependency, import 'package:thread/thread.dart'; no special permissions or build_runner needed

import 'package:thread/thread.dart';

void main() async {
  final thread = Thread((events) {
    events.on('data', (String data) async {
      await Future.delayed(const Duration(seconds: 1));
      events.emit('result', '<Computed> $data');
    });
  });

  thread.on('result', (String data) => print(data));
  thread.emit('data', 'Hello world!');
  print(await thread.compute(() => 'Hello world!'));
}

Alternatives

Packages that do the same job and could replace thread.

Works with

Packages commonly used together with thread: ones it builds on, ones built on it, and its own family.