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

Database transactions #199

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open

Conversation

michaelprichardson
Copy link
Collaborator

No description provided.

@michaelprichardson michaelprichardson marked this pull request as ready for review July 15, 2021 13:28
if (error == null && snapshot != null) {
deferred.complete(Result.success(DataSnapshot(snapshot)))
} else {
deferred.complete(Result.failure(Throwable(error?.message)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've got a database specific exception class you can throw here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 195 to 196
override fun doTransaction(currentData: MutableData) =
Transaction.success(transactionUpdate(decode(strategy, currentData)) as MutableData)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
override fun doTransaction(currentData: MutableData) =
Transaction.success(transactionUpdate(decode(strategy, currentData)) as MutableData)
override fun doTransaction(currentData: MutableData): Transaction.Result {
currentData.value = currentData.value?.let {
transactionUpdate(decode(strategy, it))
}
return Transaction.success(currentData)
}

I'm suggesting this change because I think transactions are not working.
We need to work with currentData.value, not with currentData itself.
Also we need to tolerate null value as described in the Firebase documentation.
I'm happy to help to update and merge this PR but I'm not sure I'll be able to do the same in js and iOS.

@pauminku
Copy link
Contributor

pauminku commented Jul 16, 2022

Should this PR work on iOS? I'm getting this error: Uncaught Kotlin exception: kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared <object>@xxxx from other thread

@pauminku
Copy link
Contributor

pauminku commented Jul 18, 2022

I think to make this work on iOS we'll need to freeze the callback blocks: https://youtrack.jetbrains.com/issue/KT-43566

@Reedyuk
Copy link
Collaborator

Reedyuk commented Jul 18, 2022

I think to make this work on iOS we'll need to freeze the callback blocks: https://youtrack.jetbrains.com/issue/KT-43566

I wouldnt freeze it, you should be able to enable the new memory model and disable freezing.

https://github.com/JetBrains/kotlin/blob/master/kotlin-native/NEW_MM.md

kotlin.native.binary.memoryModel=experimental
kotlin.native.binary.freezing=disabled

Freezing will be deprecated in future version of Kotlin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants