Skip to content

Commit

Permalink
Update backgroundCommit (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored Apr 23, 2024
1 parent 958c51f commit a3eb804
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Sources/Verge/Store/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ extension Store {
// MARK: - Wait
extension Store {

/**
Commit operation does not mean that emitting latest state for all of subscribers synchronously.
Updating state of the store will be updated immediately.
To wait until all of the subscribers get the latest state, you can use this method.
*/
public func waitUntilAllEventConsumed() async {
await withCheckedContinuation { c in
accept(.waiter({
Expand Down Expand Up @@ -807,9 +813,13 @@ extension Store {
mutation: (inout InoutRef<State>) throws -> Result
) async rethrows -> Result {

return try await writer.perform { [self] _ in
let result = try await writer.perform { [self] _ in
try self.commit(mutation: mutation)
}

await self.waitUntilAllEventConsumed()

return result
}

}
Expand Down
13 changes: 13 additions & 0 deletions Sources/Verge/Store/StoreDriverType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,19 @@ extension StoreDriverType where Scope == TargetStore.State {

}

extension StoreDriverType {

/**
Commit operation does not mean that emitting latest state for all of subscribers synchronously.
Updating state of the store will be updated immediately.
To wait until all of the subscribers get the latest state, you can use this method.
*/
public func waitUntilAllEventConsumed() async {
await store.asStore().waitUntilAllEventConsumed()
}
}

extension StoreDriverType {

/**
Expand Down

0 comments on commit a3eb804

Please sign in to comment.