fluffychat/lib/utils/run_in_background.dart
2021-12-03 17:29:32 +01:00

16 lines
313 B
Dart

//@dart=2.12
import 'dart:async';
import 'package:isolate/isolate.dart';
Future<T> runInBackground<T, U>(
FutureOr<T> Function(U arg) function, U arg) async {
final isolate = await IsolateRunner.spawn();
try {
return await isolate.run(function, arg);
} finally {
await isolate.close();
}
}