1616import Foundation
1717
1818internal import FirebaseInstallations
19+ internal import FirebaseCoreInternal
1920
2021protocol InstallationsProtocol : Sendable {
2122 var installationsWaitTimeInSecond : Int { get }
2223
2324 /// Override Installation function for testing
24- func authToken( completion: @escaping ( InstallationsAuthTokenResult ? , Error ? ) -> Void )
25+ func authToken( completion: @escaping @ Sendable ( InstallationsAuthTokenResult ? , Error ? ) -> Void )
2526
2627 /// Override Installation function for testing
27- func installationID( completion: @escaping ( String ? , Error ? ) -> Void )
28+ func installationID( completion: @escaping @ Sendable ( String ? , Error ? ) -> Void )
2829
2930 /// Return a tuple: (installationID, authenticationToken) for success result
3031 func installationID( completion: @escaping ( Result < ( String , String ) , Error > ) -> Void )
@@ -35,25 +36,27 @@ extension InstallationsProtocol {
3536 return 10
3637 }
3738
39+ // TODO(ncooke3): Convert o async await ahead of Firebase 12.
40+
3841 func installationID( completion: @escaping ( Result < ( String , String ) , Error > ) -> Void ) {
39- var authTokenComplete = " "
40- var installationComplete : String ?
41- var errorComplete : Error ?
42+ let authTokenComplete = FIRAllocatedUnfairLock < String > ( initialState : " " )
43+ let installationComplete = FIRAllocatedUnfairLock < String ? > ( initialState : nil )
44+ let errorComplete = FIRAllocatedUnfairLock < Error ? > ( initialState : nil )
4245
4346 let workingGroup = DispatchGroup ( )
4447
4548 workingGroup. enter ( )
4649 authToken { ( authTokenResult: InstallationsAuthTokenResult ? , error: Error ? ) in
47- authTokenComplete = authTokenResult? . authToken ?? " "
50+ authTokenComplete. withLock { $0 = authTokenResult? . authToken ?? " " }
4851 workingGroup. leave ( )
4952 }
5053
5154 workingGroup. enter ( )
5255 installationID { ( installationID: String ? , error: Error ? ) in
5356 if let installationID {
54- installationComplete = installationID
55- } else if let error = error {
56- errorComplete = error
57+ installationComplete. withLock { $0 = installationID }
58+ } else if let error {
59+ errorComplete. withLock { $0 = error }
5760 }
5861 workingGroup. leave ( )
5962 }
@@ -67,9 +70,9 @@ extension InstallationsProtocol {
6770 completion ( . failure( FirebaseSessionsError . SessionInstallationsTimeOutError) )
6871 return
6972 default :
70- if let installationComplete {
71- completion ( . success( ( installationComplete, authTokenComplete) ) )
72- } else if let errorComplete {
73+ if let installationComplete = installationComplete . value ( ) {
74+ completion ( . success( ( installationComplete, authTokenComplete. value ( ) ) ) )
75+ } else if let errorComplete = errorComplete . value ( ) {
7376 completion ( . failure( errorComplete) )
7477 }
7578 }
0 commit comments