handle method

Future<void> handle(
  1. JEffect effect,
  2. JController<T> controller,
  3. BuildContext context
)

Implementation

Future<void> handle(
  JEffect effect,
  JController<T> controller,
  BuildContext context,
) async {
  final handler = _handlers[effect.runtimeType];
  if (handler != null) {
    try {
      await handler(effect, controller, context);
    } catch (error, stackTrace) {
      _completeFailure(effect, error, stackTrace);
      rethrow;
    }

    if (kDebugMode &&
        !effect.isCompleted &&
        effect is! JFireAndForgetEffect) {
      debugPrint(
        '⚠️ [JEffect] Effect "${effect.runtimeType}" completed handler path WITHOUT completing result.\n'
        'If this effect is awaited, caller will hang. Call effect.complete(value) or effect.completeError().',
      );
    }
  } else {
    _handleUnhandled(effect);
  }
}