NitriteIsolate class
Runs a Nitrite database inside a dedicated owner isolate and lets any number of other isolates read and write the same database concurrently.
A file-backed store (e.g. Hive) cannot be opened by more than one isolate at once — independent in-memory state would diverge and concurrent writes would corrupt the file. NitriteIsolate solves this by keeping the database in a single owner isolate and serialising every operation through it. A handle is itself sendable (it wraps only a SendPort), so after spawn you can pass the same handle to as many client isolates as you like and they will all share one consistent database.
// open once on an owner isolate
final db = await NitriteIsolate.spawn(openMyDb); // openMyDb is top-level
// hand the (sendable) db to worker isolates; all share the same data
await Future.wait([
Isolate.run(() async { await db.getCollection('c').insert([doc]); }),
Isolate.run(() async { return db.getCollection('c').size; }),
]);
await db.close();
Documents, filters, find options and ids are passed by value across the isolate boundary, so results are materialised lists rather than live cursors. Typed repositories are not proxied (their converters live only in the owner) — use document collections.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
close(
) → Future< void> - Closes the database and stops the owner isolate.
-
getCollection(
String name) → IsolateCollection - A proxy to the named document collection in the owner isolate.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
spawn(
NitriteOpener factory) → Future< NitriteIsolate> -
Spawns the owner isolate, opens the database with
factorythere, and returns a sendable handle to it.