urRunBridgeStatic function

dynamic urRunBridgeStatic(
  1. Zone? zone,
  2. Function? f,
  3. String context,
  4. dynamic func(
    1. Function
    ), {
  5. dynamic defValue = null,
  6. bool nonnullable = false,
  7. bool multiApplicationCheck = false,
  8. bool reportError = true,
})

Implementation

dynamic urRunBridgeStatic(Zone? zone, Function? f,
    String context,
    dynamic Function(Function) func, {
      dynamic defValue = null,
      bool nonnullable = false,
      bool multiApplicationCheck = false,
      bool reportError = true,
    }) {
  if (f == null || zone == null) {
    try {
      throw Exception("zone is null, ${context}");
    } catch (e, stack) {
      UnitRCError.report(
          e: e, stack: stack, context: context, reportError: reportError);
      if (nonnullable) {
        rethrow;
      }
    }

    return defValue;
  }

  final block = () {
    if (multiApplicationCheck) {
      if (!UnitRCApplication.isApplicationValid()) {
        try {
          throw Exception(
              "invalid application: ${UnitRCApplication
                  .getCurrApplication()}, ${context}");
        } catch (e, stack) {
          UnitRCError.report(
              e: e, stack: stack, context: context, reportError: reportError);
          if (nonnullable) {
            rethrow;
          }
        }
        return defValue;
      }
    }
    try {
      return func(f);
    } catch (e, stack) {
      UnitRCError.report(
          e: e, stack: stack, context: context, reportError: reportError);
      return defValue;
    }
  };

  if (identical(Zone.current, zone)) {
    return block();
  } else {
    return zone.run(() {
      return block();
    });
  }
}