dart_thread 0.0.5 copy "dart_thread: ^0.0.5" to clipboard
dart_thread: ^0.0.5 copied to clipboard

Mapping isolates and web workers to single interface, that allow to write one code for different platforms

example/lib/main.dart

import 'dart:math';
import 'package:dart_thread/dart_thread.dart';

class TestThread extends DartThread {

  // Need to mapping Class to super.init,
  // because dart did not allow override a static method
  static TestThread newInstance() => TestThread();

  @override
  Future<void> onExecute(Function(dynamic message) sendMessage) async {

    while (true) {
      sendMessage(Random().nextInt(100));
      await Future.delayed(Duration(seconds: 1));
    }

  }

  @override
  Future<void> onGetMessage(message, Function(dynamic message) sendMessage) async {

    sendMessage(message);

  }

}

void main() async {

  TestThread testThread = TestThread();

  await testThread.init(TestThread.newInstance, (message) {

    print(message);

  });

  testThread.sendMessage('echo');

  await Future.delayed(Duration(seconds: 10));

  testThread.deInit();

}
8
likes
0
pub points
61%
popularity

Publisher

verified publishervsgroup.ua

Mapping isolates and web workers to single interface, that allow to write one code for different platforms

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on dart_thread