worker_manager 4.3.4 copy "worker_manager: ^4.3.4" to clipboard
worker_manager: ^4.3.4 copied to clipboard

Executor allows you to create a queue of tasks for isolate pool

example/lib/main.dart

// Copyright Daniil Surnin. All rights reserved.
// Use of this source code is governed by a Apache license that can be
// found in the LICENSE file.

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:worker_manager/worker_manager.dart';

void main() async {
  await Executor().warmUp(log: true);
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(

      showPerformanceOverlay: true,
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

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

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final computeResults = [];
  final executorResults = [];
  var computeTaskRun = 0;
  var executorTaskRun = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text("Fibonacci calculation of 43 "),
            const CircularProgressIndicator(),
            Row(
              children: [
                Text(computeTaskRun.toString()),
                Spacer(),
                Text(executorTaskRun.toString()),
              ],
            ),
            const SizedBox(
              height: 200,
            ),
            Text('Results'),
            Row(
              children: [
                Text(computeResults.length.toString()),
                Spacer(),
                Text(executorResults.length.toString()),
              ],
            ),
            Row(
              children: [
                CupertinoButton(
                  child: Text('run compute'),
                  onPressed: () {
                    setState(() {
                      computeTaskRun++;
                      compute(fib, 43).then((value) {
                        setState(() {
                          computeResults.add(value);
                        });
                      });
                    });
                  },
                ),
                Spacer(),
                CupertinoButton(
                  child: Text('run executor'),
                  onPressed: () {
                    setState(() {
                      executorTaskRun++;
                      Executor().execute(arg1: 43, fun1: fib).then((value) {
                        setState(() {
                          executorResults.add(value);
                        });
                      });
                    });
                  },
                )
              ],
            ),
          ],
        ),
      ),
    );
  }
}

int fib(int n) {
  if (n < 2) {
    return n;
  }
  return fib(n - 2) + fib(n - 1);
}
300
likes
0
pub points
94%
popularity

Publisher

verified publisherrenesanse.net

Executor allows you to create a queue of tasks for isolate pool

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

async, collection

More

Packages that depend on worker_manager