thread 0.2.2 copy "thread: ^0.2.2" to clipboard
thread: ^0.2.2 copied to clipboard

A simple Isolated Thread wrapped with a type-safe Event Emitter for easier asynchronous communication. Setup events for the thread to reply to, or compute tasks individually.

example/main.dart

// ignore_for_file: avoid_print

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!');
  thread.emit('data', 'Wow!');

  print(await thread.compute(() => 'Hello world!'));
  print(await thread.computeWith(123, (int data) => 'Wow $data'));

  // [Output]
  // Hello world!
  // Wow 123

  // <Computed> Hello world!
  // <Computed> Wow!
}
12
likes
150
points
1.43k
downloads

Publisher

verified publisherdrafakiller.com

Weekly Downloads

A simple Isolated Thread wrapped with a type-safe Event Emitter for easier asynchronous communication. Setup events for the thread to reply to, or compute tasks individually.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

async_signal, events_emitter, uuid

More

Packages that depend on thread