Skip to content

Commit 3e1761d

Browse files
Store clone: clarify why model can not be sent, note close behavior.
1 parent e284339 commit 3e1761d

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

objectbox/lib/src/native/store.dart

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ class Store {
5757
/// A list of observers of the Store.close() event.
5858
final _onClose = <dynamic, void Function()>{};
5959

60-
/// Creates a BoxStore using the model definition from the generated
61-
/// whether this store was created from a pointer (won't close in that case)
60+
/// If weak and calling [close] does not try to close the native Store and
61+
/// remove [_absoluteDirectoryPath] from [_openStoreDirectories].
6262
final bool _weak;
6363

6464
/// Default value for string query conditions [caseSensitive] argument.
@@ -223,16 +223,13 @@ class Store {
223223
}
224224
}
225225

226-
/// Returns a minimal Store that only has a reference to a native store,
227-
/// without any info like model definition, database directory and others.
226+
/// Creates a Store clone with minimal functionality given a pointer address
227+
/// obtained by [_clone].
228228
///
229-
/// This store is e.g. good enough to start a transaction, but does not allow
230-
/// to e.g. use boxes. This is useful when creating a store within another
231-
/// isolate as only information that can be sent to an isolate is necessary
232-
/// (the store and model definition contain pointers that can not be sent to
233-
/// an isolate).
229+
/// Only has a reference to a native store, has no model definition. E.g. is
230+
/// good enough to start a transaction, but does not allow to use boxes.
234231
///
235-
/// Obtain a [ptrAddress] from [_clone], see it for more details.
232+
/// See [_clone] for details.
236233
Store._minimal(int ptrAddress, {bool queriesCaseSensitiveDefault = true})
237234
: _defs = null,
238235
_weak = false,
@@ -365,15 +362,19 @@ class Store {
365362
///
366363
/// The address of the pointer can be used with [Store._minimal].
367364
///
368-
/// This can be useful to work with isolates as it is not possible to send a
369-
/// [Store] to an isolate (the Store itself and the contained model definition
370-
/// contain pointers). Instead, send the pointer address returned by this
371-
/// and create a minimal store (for limitations see [Store._minimal]) in the
372-
/// isolate. Make sure to [close] the clone as well before the isolate exits.
365+
/// This can be useful to access the same Store in another isolate as it is
366+
/// not possible to send a [Store] to an isolate (Store contains Pointer which
367+
/// can not be sent, ModelDefinition contains Function which can only be sent
368+
/// on Dart SDK 2.15 or higher). Instead, send the pointer address returned by
369+
/// this and create a minimal store in the isolate. For limitations see
370+
/// [Store._minimal].
371+
///
372+
/// Make sure to [close] the clone before the isolate exits. The native store
373+
/// remains open until all clones and the original Store are closed.
373374
///
374375
/// ```dart
375376
/// // Clone the store and obtain its address, can be sent to an isolate.
376-
/// final storePtrAddress = store.clone().address;
377+
/// final storePtrAddress = InternalStoreAccess.clone(store).address;
377378
///
378379
/// // Within an isolate create a minimal store.
379380
/// final store = InternalStoreAccess.createMinimal(isolateInit.storePtrAddress);

0 commit comments

Comments
 (0)