fluffychat/lib/utils/run_in_background.dart

14 lines
299 B
Dart
Raw Normal View History

import 'dart:async';
2021-10-26 18:50:34 +02:00
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();
}
}