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 {
  final releasePool = <Ref>{};
  try {
    if (android != null && Platform.isAndroid) {
      return await android(releasePool);
    } else if (ios != null && Platform.isIOS) {
      return await ios(releasePool);
    } else {
      return Future.value();
    }
  } catch (e) {
    return Future.error(e);
  } finally {
    if (releasePool.isNotEmpty) {
      await releasePool.release_batch();
      releasePool.clear();
      // remove all local object from global object pool
      kNativeObjectPool.removeAll(releasePool);
    }
  }
}