createLayers static method

Future<Layer> createLayers(
  1. List<(fnInitLayer, Object?, bool)> layers, {
  2. bool currentIsModelBus = true,
  3. Duration? timeout,
})

Layers create layer what split by isolate. Top layer have current and bottom eventbus, bottom eventbus this is EventBusIsolate, middle layer have top eventbus for connect to top layer and bottom eventbus for cnnect bottom layer if they present

(fnInitLayer,Object?,bool) - inital function, inital data, flag what create model current bus in isolate

The future completes when EVERY layer of the chain is initialized, including async init functions. An init failure of any layer surfaces here as well. timeout limits the wait (unlimited by default).

Implementation

static Future<Layer> createLayers(List<(fnInitLayer, Object?, bool)> layers,
    {bool currentIsModelBus = true, Duration? timeout}) async {
  if (layers.isEmpty) {
    throw EventBusException('Layers.createLayers: layers list must not be empty');
  }

  _LayerInitDto storage = _LayerInitDto(data: layers, index: 0);

  Layer l = Layer(
      current: EventBus(isModelBus: currentIsModelBus),
      bottom: EventBusIsolate(onInit: _initLayer, initalData: storage));
  var waitInit = (l.bottom as EventBusIsolate).waitInit;
  if (timeout != null) {
    await waitInit.timeout(timeout, onTimeout: () {
      throw EventBusException('Layers.createLayers: initialization timeout ($timeout)');
    });
  } else {
    await waitInit;
  }
  return l;
}