File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
firebase-dataconnect/src/main/kotlin/com/google/firebase/dataconnect/core Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -484,6 +484,29 @@ internal class FirebaseDataConnectImpl(
484484 is State .Closing -> newState.closeJob.apply { start() }
485485 is State .Closed -> null
486486 }
487+
488+ // Register the new "close job". Do not overwrite a close job that is already in progress (to
489+ // avoid having more than one close job in progress at a time) or a close job that completed
490+ // successfully (since there is nothing to do if a previous close job was successful).
491+ val updatedCloseJobRef =
492+ closeJob.updateAndGet { currentCloseJobRef: NullableReference <Deferred <Unit >> ->
493+ if (currentCloseJobRef.ref != = null && ! currentCloseJobRef.ref.isCancelled) {
494+ currentCloseJobRef
495+ } else {
496+ NullableReference (newCloseJob)
497+ }
498+ }
499+
500+ // Start the updated "close job" (if it was already started then start() is a no-op).
501+ val updatedCloseJob =
502+ checkNotNull(updatedCloseJobRef.ref) {
503+ " internal error: closeJob.updateAndGet() returned a NullableReference whose 'ref' " +
504+ " property was null; however it should NOT have been null (error code y5fk4ntdnd)"
505+ }
506+ updatedCloseJob.start()
507+
508+ // Return the "close job", which _may_ already be completed, so the caller can await it.
509+ return updatedCloseJob
487510 }
488511
489512 // The generated SDK relies on equals() and hashCode() using object identity.
You can’t perform that action at this time.
0 commit comments