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.

Libraries

annotations
common
common_web
globals
grunt
grunt_channel
grunt_platform_interface
grunt_platform_native
grunt_platform_web
grunt_platform_webworker
grunt_registry
isolate_entry
message
ports
ports_shared
supervisor
utils
web_worker
work
work
work
work_proxy_native
work_proxy_platform
work_proxy_web
worker_service
worker_service_interface
worker_service_isolate
worker_service_web

VM

ports VM
Concurrent programming using isolates: independent workers that are similar to threads but don't share memory, communicating only via messages. [...]