start method

Future<void> start()

Implementation

Future<void> start() async {
  Future<List<Future<void> Function()>>? waiter;
  await pool.start(root);
  if (reloadable) {
    PrecisionStopwatch hotloadClock = PrecisionStopwatch.start();
    List<Node>? hotloadNodes;
    String hlk = "@(#db03fc) &r ";
    _reloader = await HotReloader.create(
        automaticReload: true,
        debounceInterval: Duration(milliseconds: 250),
        watchDependencies: false,
        onBeforeReload: (v) {
          String? p = v.event?.path;
          hotloadNodes =
              pool.nodes.where((i) => i.$sourceCodeFile == p).toList();

          if (hotloadNodes!.isNotEmpty) {
            hotloadClock = PrecisionStopwatch.start();
            String names = hotloadNodes!.map((i) => i.nodeName).join(", ");
            _reloadLogger
                .info("HotReloading ${hotloadNodes!.length} nodes: $names");
            PLogger.modifiers.add(hlk);
            waiter =
                Future.wait(hotloadNodes!.map((i) => i.destroyWithStarter()));

            return true;
          }

          return false;
        },
        onAfterReload: (v) async {
          switch (v.result) {
            case HotReloadResult.Skipped:
              PLogger.modifiers.remove(hlk);
              _reloadLogger.verbose("HotReload skipped.");
            case HotReloadResult.Failed:
              PLogger.modifiers.remove(hlk);
              _reloadLogger.error("HotReload failed.");
            case HotReloadResult.PartiallySucceeded:
              PLogger.modifiers.remove(hlk);
              _reloadLogger.warn(
                  "HotReload partially succeeded. Some nodes may not have been reloaded.");
            case HotReloadResult.Succeeded:
              await Future.wait((await (waiter!)).map(((i) => i())));
              PLogger.modifiers.remove(hlk);
              _reloadLogger.success(
                  "HotReload succeeded in ${hotloadClock.getMilliseconds().toStringAsFixed(0)}ms.");
              hotloadNodes = null;
          }
        });
  }
  PLogger.modifiers.remove(_sk);
  logger.success(
      "PhantomServer started in ${clock.getMilliseconds().toStringAsFixed(0)}ms.");
}