invoke method

  1. @nonVirtual
Future<void> invoke(
  1. JController<T> controller
)
inherited

Wires the controller before executing the logic. Not overridable; override onInvoke instead. An instance can be reused after completion, but overlapping invocations fail with StateError before rebinding it. Invoking against a disposed controller also fails with StateError.

Implementation

@nonVirtual
Future<void> invoke(JController<T> controller) async {
  if (_isRunning) {
    throw StateError('$runtimeType is already running.');
  }
  if (!controller.mounted) {
    throw StateError('Cannot invoke $runtimeType on a disposed controller.');
  }
  _isRunning = true;
  _isCancelled = false;
  _controller = controller;
  try {
    JObserver.notifyIntentStarted(this);
    await runZoned(onInvoke, zoneValues: {_currentIntentKey: this});
  } catch (error, stackTrace) {
    JObserver.notifyIntentFailed(this, error, stackTrace);
    rethrow;
  } finally {
    _isRunning = false;
  }
}