Skip to content

Commit

Permalink
Async APIs: rename Store await APIs to avoid mix-up with async #50
Browse files Browse the repository at this point in the history
  • Loading branch information
greenrobot-team committed Mar 7, 2023
1 parent de25b15 commit 541575c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions benchmark/bin/write.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class PutAsyncToList extends DbBenchmark {
Future<void> run() async {
final futures = items.map(box.putQueuedAwaitResult).toList(growable: false);
await Future.wait(futures);
store.awaitAsyncSubmitted();
store.awaitQueueSubmitted();
}
}

Expand All @@ -125,7 +125,7 @@ class PutAsyncAwait extends DbBenchmark {
@override
Future<void> run() async {
items.forEach((item) async => await box.putQueuedAwaitResult(item));
store.awaitAsyncSubmitted();
store.awaitQueueSubmitted();
}
}

Expand All @@ -137,7 +137,7 @@ class PutQueued extends DbBenchmark {
@override
Future<void> run() async {
items.forEach(box.putQueued);
store.awaitAsyncSubmitted();
store.awaitQueueSubmitted();
}
}

Expand Down
3 changes: 3 additions & 0 deletions objectbox/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
`store.runInTransactionAsync`. #340
* `Store.fromReference` and `Store.attach` do not longer accept a null model, which was not
supported anyhow.
* The former `Box.putAsync` has moved to `Box.putQueuedAwaitResult`.
* Breaking change: `awaitAsyncSubmitted` and `awaitAsyncCompletion` on `Store` are renamed to
`awaitQueueSubmitted` and `awaitQueueCompletion` to avoid any mix-up with the new async methods.

## 1.7.2 (2023-01-31)

Expand Down
2 changes: 1 addition & 1 deletion objectbox/lib/src/native/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class Box<T> {
/// parallel (e.g. this is called many times) for better performance.
///
/// To wait on the completion of submitted operations, use
/// [Store.awaitAsyncSubmitted] or [Store.awaitAsyncCompletion].
/// [Store.awaitQueueSubmitted] or [Store.awaitQueueCompletion].
///
/// The actual database put operation may fail even if this returned
/// normally (and even if a new ID for a new object was returned), for example
Expand Down
16 changes: 8 additions & 8 deletions objectbox/lib/src/native/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -767,27 +767,27 @@ class Store {
/// available. Use [Sync.client()] to create one first.
SyncClient? syncClient() => syncClientsStorage[this];

/// Await for all (including future) async submissions to be completed
/// (the async queue becomes idle for a moment).
/// Await for all (including future) submissions using [Box.putQueued] to be
/// completed (the queue becomes idle for a moment).
///
/// Returns true if all submissions were completed or async processing was
/// Returns true if all submissions were completed or processing was
/// not started; false if shutting down (or an internal error occurred).
///
/// Use to wait until all puts by [Box.putQueued] have finished.
bool awaitAsyncCompletion() {
bool awaitQueueCompletion() {
final result = C.store_await_async_submitted(_ptr);
reachabilityFence(this);
return result;
}

/// Await for previously submitted async operations to be completed
/// (the async queue does not have to become idle).
/// Await for previously submitted operations using [Box.putQueued] to be
/// completed (the queue does not have to become idle).
///
/// Returns true if all submissions were completed or async processing was
/// Returns true if all submissions were completed or processing was
/// not started; false if shutting down (or an internal error occurred).
///
/// Use to wait until all puts by [Box.putQueued] have finished.
bool awaitAsyncSubmitted() {
bool awaitQueueSubmitted() {
final result = C.store_await_async_submitted(_ptr);
reachabilityFence(this);
return result;
Expand Down
4 changes: 2 additions & 2 deletions objectbox/test/box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void main() {
for (int i = 0; i < items.length; i++) {
expect(items[i].id, ids[i]);
}
store.awaitAsyncSubmitted();
store.awaitQueueSubmitted();
expect(box.count(), items.length);
});

Expand All @@ -216,7 +216,7 @@ void main() {
throwsA(predicate((ArgumentError e) =>
e.toString().contains('Use ID 0 (zero) to insert new entities'))));

store.awaitAsyncCompletion();
store.awaitQueueCompletion();
expect(store.box<TestEntity2>().count(), 0);
expect(store.box<TestEntityNonRel>().count(), 0);
});
Expand Down

0 comments on commit 541575c

Please sign in to comment.