thread 0.0.3 copy "thread: ^0.0.3" to clipboard
thread: ^0.0.3 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

import 'package:thread/thread.dart';

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

  thread.on('result', (String data) => print(data));

  thread.emit('compute', 'Hello world!');
  thread.emit('compute', 'Wow!');

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

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

  // Hello world!
  // Wow 123
}
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