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

Asynchronous Database Access Methods #550

Merged
merged 10 commits into from
Jun 14, 2019
Merged

Asynchronous Database Access Methods #550

merged 10 commits into from
Jun 14, 2019

Conversation

groue
Copy link
Owner

@groue groue commented Jun 13, 2019

This PR adds asynchronous database access methods on DatabaseQueue, Pool, and Snaphot:

protocol DatabaseReader {
    #if compiler(>=5.0)
    func asyncRead(_ block: @escaping (Result<Database, Error>) -> Void)
    #endif
}

protocol DatabaseWriter {
    #if compiler(>=5.0)
    func asyncWrite<T>(
        _ updates: @escaping (Database) throws -> T,
        completion: @escaping (Database, Result<T, Error>) -> Void)
    #endif

    func asyncWriteWithoutTransaction(_ updates: @escaping (Database) -> Void)
}

asyncWrite and asyncRead use the Result type from the Standard Library, and are only available with a Swift 5+ compiler (Xcode 10.2+).

I'm worried that asyncWriteWithoutTransaction is easier to use than the safer alternative asyncWrite. Let's hope the very long name sounds like a warning for the users.

Those methods will fuel RxGRDB and GRDBCombine.

@groue groue added this to the GRDB 4.1.0 milestone Jun 13, 2019
@groue
Copy link
Owner Author

groue commented Jun 14, 2019

Yeah @sobri909, it took years of iterations, and the advent of the standard Result, before we could shape the asynchronous APIs 😅

@sobri909
Copy link
Collaborator

@groue I didn't even know this was in the works! Very cool surprise 😄

Also, apologies for being absent for the past many months. My workload has been insane, and drowned out my chances to work on anything else. But I do still read every GRDB email 😂 There's always fun new things turning up! I just never have the time to start using them or work on them. Sigh.

I'm keen to have a play with GRDBCombine though, once I get a chance. That looks extremely promising!

@groue
Copy link
Owner Author

groue commented Jun 14, 2019

Don't worry :-) I'm having a lot of fun, and it's a pleasure to share it 👍

@groue groue merged commit 66552eb into development Jun 14, 2019
@groue groue deleted the dev/async branch June 14, 2019 16:58
@groue groue mentioned this pull request Jun 14, 2019
10 tasks
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.

2 participants