platform<T> function

Future<T> platform<T>(
  1. {_FutureCallback<T> android,
  2. _FutureCallback<T> ios}
)

Implementation

Future<T> platform<T>({
  _FutureCallback<T> android,
  _FutureCallback<T> ios,
}) async {
  if (android != null && Platform.isAndroid) {
    final releasePool = <Ref>{};
    T result;
    try {
      result = await android(releasePool);
    } catch (e) {
      return Future.error(e);
    } finally {
      releasePool
        ..forEach(release)
        ..clear();
      // remove all local object from global object pool
      kNativeObjectPool.removeAll(releasePool);
    }
    return result;
  } else if (ios != null && Platform.isIOS) {
    final releasePool = <Ref>{};
    T result;
    try {
      result = await ios(releasePool);
    } catch (e) {
      return Future.error(e);
    } finally {
      releasePool
        ..forEach(release)
        ..clear();
      // remove all local object from global object pool
      kNativeObjectPool.removeAll(releasePool);
    }
    return result;
  } else {
    return Future.value();
  }
}