hotReload method

Future<void> hotReload(
  1. Module newModule
)
inherited

Performs a hot reload by replacing this module with a new implementation.

This advanced feature allows updating module code without losing state. Use with caution in production environments.

Parameters:

  • newModule - The new module implementation to replace this one

Note: This is primarily intended for development scenarios.

Implementation

Future<void> hotReload(Module newModule) async {
  info('Hot reloading module $name');

  try {
    // Suspend current module
    if (_state == ModuleLifecycleState.active) {
      await suspend();
    }

    // Transfer state to new module
    await onHotReload(newModule);

    // Initialize new module
    await newModule.initialize();

    info('Hot reload completed for module $name');
  } catch (e) {
    error('Hot reload failed for module $name: $e');
    await _transitionTo(ModuleLifecycleState.error, error: e);
    rethrow;
  }
}