Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatabaseRegionObservation #455

Merged
merged 15 commits into from
Dec 7, 2018
Merged

Conversation

groue
Copy link
Owner

@groue groue commented Dec 6, 2018

This PR continues the job of moving some RxGRDB features back to GRDB, so that we can share code between reactive engines (and even not use any reactive engine at all).

DatabaseRegionObservation is like ValueObservation, except that it does not notify fresh values on every change. Instead, it notifies all impactful transactions right after they have been committed, and before any other thread had any opportunity to perform further changes:

let observation = DatabaseRegionObservation(tracking: Player.all())
let observer = observation.start(in: dbQueue) { db: Database in
    print("Players were changed")
}

try dbQueue.write { db in
    try Player(name: "Arthur").insert(db)
}
// Prints "Players were changed"

DatabaseRegionObservation is not a tool that should be used frequently. The intended use cases are all pretty advanced:

  • One needs to write in the database after an impactful transaction.

  • One needs to synchronize the content of the database file with some external resources, like other files, or system sensors like CLRegion monitoring.

  • On iOS, one needs to process a database transaction before the operating system had any opportunity to put the application in the suspended state.

  • One want to build a database snapshot with a guaranteed snapshot content.

@groue groue added this to the GRDB 3.6.0 milestone Dec 6, 2018
@groue groue merged commit 32acfb2 into development Dec 7, 2018
@groue groue deleted the feature/DatabaseRegionObserver branch December 7, 2018 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant