DriftIsolate class
Defines utilities to run drift in a background isolate. In the operation mode created by these utilities, there's a single background isolate doing all the work. Any other isolate can use the connect method to obtain an instance of a GeneratedDatabase class that will delegate its work onto a background isolate. Auto-updating queries, and transactions work across isolates, and the user facing api is exactly the same.
Please note that, while running drift in a background isolate can reduce latency in foreground isolates (thus reducing UI lags), the overall performance is going to be much worse as data has to be serialized and deserialized to be sent over isolates. Also, be aware that this api is not available on the web.
See also:
- Isolate, for general information on multi threading in Dart.
- The detailed documentation, which provides example codes on how to use this api.
Constructors
- DriftIsolate.fromConnectPort(SendPort connectPort, {bool serialize = true})
-
Creates a DriftIsolate talking to another isolate by using the
connectPort
. - DriftIsolate.inCurrent(DatabaseOpener opener, {bool killIsolateWhenDone = false, bool serialize = false})
-
Creates a DriftIsolate in the Isolate.current isolate. The returned
DriftIsolate is an object than can be sent across isolates - any other
isolate can then use DriftIsolate.connect to obtain a special database
connection which operations are all executed on this isolate.
factory
Properties
- connectPort → SendPort
-
The underlying port used to establish a connection with this
DriftIsolate.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serialize → bool
-
The flag indicating whether messages between this DriftIsolate
and the
DriftServer
should be serialized.final
Methods
-
connect(
{bool isolateDebugLog = false}) → Future< DatabaseConnection> - Connects to this DriftIsolate from another isolate.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
shutdownAll(
) → Future< void> - Stops the background isolate and disconnects all DatabaseConnections created. If you only want to disconnect a database connection created via connect, use GeneratedDatabase.close instead.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
spawn(
DatabaseOpener opener, {bool serialize = false}) → Future< DriftIsolate> - Creates a new DriftIsolate on a background thread.