dyno 0.0.4 copy "dyno: ^0.0.4" to clipboard
dyno: ^0.0.4 copied to clipboard

An isolation pool with load balancer for Flutter. Creates and kills isolates as needed.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:dyno/dyno.dart' as dyno;

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) => const MaterialApp(home: Demo());
}

class Demo extends StatefulWidget {
  const Demo({Key? key}) : super(key: key);

  @override
  State<Demo> createState() => _DemoState();
}

class _DemoState extends State<Demo> {
  int _executionTime = 0;

  Future<void> measureRun() async {
    final stopwatch = Stopwatch()..start();

    // Calculate the 100,000th Fibonacci number isolated.
    await dyno.run<int>(() async {
      int n1 = 0, n2 = 1;
      late int n3;

      for (int i = 2; i <= 10000000; i++) {
        n3 = n1 + n2;
        n1 = n2;
        n2 = n3;
      }

      return n3;
    });

    setState(() => _executionTime = stopwatch.elapsed.inMilliseconds);
    stopwatch.reset();
  }

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Center(child: Text('Execution time in ms: $_executionTime')),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: measureRun,
        child: const Text('Start'),
      ),
    );
  }
}
6
likes
160
pub points
58%
popularity

Publisher

verified publishersourcekod.com

An isolation pool with load balancer for Flutter. Creates and kills isolates as needed.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on dyno