squadron_builder 0.7.0 copy "squadron_builder: ^0.7.0" to clipboard
squadron_builder: ^0.7.0 copied to clipboard

outdated

Dart code generator for Squadron workers. Implement your worker service and let squadron_builder bridge the gap with Web Workers and Isolates!

example/main.dart

import 'dart:async';

import 'package:squadron/squadron.dart';

import 'my_service.dart';

void main() async {
  Squadron.setId('MAIN');
  Squadron.setLogger(ConsoleSquadronLogger());
  Squadron.logLevel = SquadronLogLevel.info;

  int count = 5;

  Squadron.info('Computing with MyService (single-threaded)');
  await computeWith(MyService(), count);

  Squadron.info('Computing with MyServiceWorkerPool (multi-threaded)');
  final pool = MyServiceWorkerPool(
      concurrencySettings: ConcurrencySettings(
    minWorkers: count,
    maxWorkers: count,
    maxParallel: 1,
  ));
  await pool.start();
  await computeWith(pool, count);
  pool.stop();
}

Future computeWith(MyService service, int count) async {
  final sw = Stopwatch();
  sw.start();

  final futures = <Future<int>>[];
  for (var i = 0; i < count; i++) {
    futures.add(service.fibonacci(40 + i));
  }

  final results = await Future.wait(futures);
  Squadron.info('  * Results = $results');
  Squadron.info('  * Total elapsed time: ${sw.elapsed}');
  sw.stop();
}
20
likes
0
pub points
81%
popularity

Publisher

unverified uploader

Dart code generator for Squadron workers. Implement your worker service and let squadron_builder bridge the gap with Web Workers and Isolates!

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

analyzer, build, source_gen, squadron

More

Packages that depend on squadron_builder