single<T> static method

Future<T> single<T>(
  1. Object? intialValue,
  2. Future<T> test(
    1. Object? data
    )
)

Implementation

static Future<T> single<T>(
  Object? intialValue,
  Future<T> Function(Object? data) test,
) async {
  final BuildIsolate isolate = BuildIsolate();
  final Completer<T> completer = Completer<T>();
  await isolate.init(
    onIsolateDataRecived: (data, sendPort) async {
      printAmber("$data", prefix: "isolate");
      // sendPort.send(await test(data));
    },
    onDataRecived: (data, sendPort) {
      printAmber("$data", prefix: "main");
      // if (data is T) completer.complete(data);
    },
  );
  completer.future.then((value) => isolate.dispose());
  return completer.future;
}