EasyWorker constructor
EasyWorker(})
Implementation
EasyWorker(
void Function(SendPort from) entrypoint, {
required String workerName,
dynamic initialMessage,
bool paused = false,
bool errorsAreFatal = true,
SendPort? onExit,
SendPort? onError,
}) : _fromIsolate = ReceivePort(workerName) {
_fromIsolate.listen((message) {
if (message is SendPort) {
_toIsolate = message;
if (!_firstMessageDelivered) {
send(initialMessage);
_firstMessageDelivered = true;
}
return;
}
_controller.sink.add(message);
});
Isolate.spawn(
entrypoint,
_fromIsolate.sendPort,
debugName: "Worker: $workerName",
paused: paused,
onExit: onExit,
onError: onError,
errorsAreFatal: errorsAreFatal,
).then((value) {
isolate = value;
Future.delayed(
const Duration(milliseconds: 50), () => _ready.complete(true));
});
}