worker_service 0.7.4 copy "worker_service: ^0.7.4" to clipboard
worker_service: ^0.7.4 copied to clipboard

A flutter package that works for native/web, and allows the creation of workers that offload work into a potentially parallel space

worker_service #

pub package Coverage Status

A flutter package that uses the isolate package, and adds some convenience for working with isolates in Flutter. Isolates spawned with this library will be automatically destroyed and recreated when using hot-restart in Flutter. This library does not allow the use of Flutter plugins within isolates.

Getting Started #

You can register initialization globally, so that all isolates spawned using the library will run the same initialization


// This runs whenever an `IsolateRunner` is spawned - this runs in the spawning isolate, so it accepts
// closures
RunnerFactory.global.onIsolateCreated((IsolateRunner runner) {
    
});

// This registers a function to be run _inside_ the newly spawned isolate
RunnerFactory.global.addIsolateInitializer(_setupLogging, Level.INFO);

_setupLogging(Level info) {
...
}

/// Instead of registering globally, you can create your own custom factory
final customFactory = RunnerFactory()
    ..addIsolateInitializer(_setupLogging, Level.INFO)
    ..onIsolateCreated(...);

To spawn an isolate Runner, call the spawn method on RunnerFactory


Runner runner = await RunnerFactory.global.spawn((builder) =>  builder
  ..autoclose = true
  ..debugName = "processor"
  ..poolSize = 3
);

By default, any spawned Runner instances will be automatically closed when the parent Isolate terminates.

4
likes
100
pub points
22%
popularity

Publisher

verified publishersunnyapp.co

A flutter package that works for native/web, and allows the creation of workers that offload work into a potentially parallel space

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

async, collection, dartxx, equatable, isolates, js, logging, logging_config, meta, uuid

More

Packages that depend on worker_service