init method

  1. @override
void init(
  1. ProImageEditorConfigs configs
)
override

Initializes the thread manager with the provided configuration settings.

configs - The configuration settings for the image editor.

Implementation

@override
void init(ProImageEditorConfigs configs) async {
  processorConfigs = configs.imageGenerationConfigs.processorConfigs;

  int processors = getNumberOfProcessors(
    configs: configs.imageGenerationConfigs.processorConfigs,
    deviceNumberOfProcessors: Platform.numberOfProcessors,
  );
  for (var i = 0; i < processors && !isDestroyed; i++) {
    var isolate = IsolateThread(
      coreNumber: i + 1,
      onMessage: (message) {
        int i = tasks.indexWhere((el) => el.taskId == message.id);
        if (i >= 0) tasks[i].bytes$.complete(message.bytes);
      },
    );
    threads.add(isolate);

    /// Await that isolate is ready before spawn a new one.
    await isolate.readyState.future;
    isolate.isReady = true;
    if (isDestroyed) {
      isolate.destroy();
    }
  }
}