isolates_helper 0.4.3+1 copy "isolates_helper: ^0.4.3+1" to clipboard
isolates_helper: ^0.4.3+1 copied to clipboard

Creates multiple long-lived isolates to compute multiple functions; Supports Worker and WASM on the Web; Supports try-catch block

example/lib/main.dart

import 'dart:math';

import 'package:flutter/material.dart';
import 'package:isolates_helper/isolates_helper.dart';

import 'functions.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String text = '';

  final isolates = IsolatesHelper(
    concurrent: 3,
    worker: 'worker',
    isDebug: true,
  );

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

  void calculate() {
    final rand = Random();
    final params = [rand.nextInt(1000), rand.nextInt(1000)];
    isolates(add, params, workerFunction: 'add').then((value) {
      setState(() => text = '$value');
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
            child: Column(
          children: [
            Text('Result: $text'),
            ElevatedButton(onPressed: calculate, child: const Text('Calculate'))
          ],
        )),
      ),
    );
  }
}
5
likes
140
pub points
64%
popularity

Publisher

verified publisherlamnhan.dev

Creates multiple long-lived isolates to compute multiple functions; Supports Worker and WASM on the Web; Supports try-catch block

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

isolate_manager

More

Packages that depend on isolates_helper