Reputation: 4277
I have read the documentation about the batched writes
, but I didn't understand when does the onSuccess
method is reached:
Or none of the above...
Thanks.
Upvotes: 1
Views: 573
Reputation: 6926
The WriteBatch#commit()
method, like other Firestore write and read operations, spawns and returns a Task
instance that will perform the work in the background.
Success listeners attached to this Task
will be called if the task completes successfully. It's a bit like attaching a complete listener and then checking that the task result was successful.
In the case of BatchWrite
, all of the writes in the batch are committed as a single atomic unit, so will only return success if all of the writes were successful.
Upvotes: 3
Reputation: 16309
A batch write is atomic and so it will either successfully complete all of the writes, or it will fail all of the writes.
So once the batch write completes, it will call the onSuccess()
method if it was successful and all writes were committed, or it will call the onFailure()
method if it was not successful and none of the writes were committed.
Upvotes: 1