then<T> function

FutureOr<T> then<T>(
  1. String description,
  2. FutureOr<T> body()
)

Implementation

FutureOr<T> then<T>(String description, FutureOr<T> Function() body) {
  final thens = Zone.current[thenKey] as List<String>?;

  if (thens == null) throw Exception('Use gwt method');

  final state = Zone.current[stateKey] as State;
  state.key = thenKey;
  thens.add(description);

  final result = body();

  if (result is Future) {
    return Future.sync(() async => await result);
  } else {
    return result;
  }
}