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

outdated

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/lib/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
0
pub points
83%
popularity

Publisher

verified publisherdrafakiller.com

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

License

unknown (license)

Dependencies

async_signal, events_emitter, uuid

More

Packages that depend on thread