compute<T> static method
Runs computation
in a new isolate and returns the result. Also takes
care of initializing Hive and closing all boxes afterwards.
The optional debugName
can be used to identify the isolate in debuggers.
Implementation
static Future<T> compute<T>(
FutureOr<T> Function() computation, {
String? debugName,
}) {
final registry = _typeRegistry;
final dir = defaultDirectory;
return Isolate.run(
() async {
Hive._typeRegistry = registry;
Hive.defaultDirectory = dir;
try {
return await computation();
} finally {
Hive.closeAllBoxes();
}
},
debugName: debugName ?? 'Hive Isolate',
);
}