Skip to content

Commit b00fcf9

Browse files
committed
Minor changes in structure, comments
1 parent 106c60a commit b00fcf9

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/src/main/java/at/bitfire/cert4android/UserDecisionRegistry.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,28 @@ class UserDecisionRegistry private constructor(
5454
}
5555
}
5656

57-
val requestDecision: Boolean
5857
synchronized(pendingDecisions) {
5958
if (pendingDecisions.containsKey(cert)) {
6059
// There are already pending decisions for this request, just add our request
6160
pendingDecisions[cert]!! += cont
62-
requestDecision = false
61+
6362
} else {
64-
// First decision for this certificate, show UI
63+
// First decision for this certificate, add to map and show UI
6564
pendingDecisions[cert] = mutableListOf(cont)
66-
requestDecision = true
65+
66+
scope.launch {
67+
val userDecision = getUserDecision(cert) // suspends until user decision is made
68+
69+
// resume all coroutines that are waiting for a decision
70+
resumeOnUserDecision(cert, userDecision)
71+
}
6772
}
6873
}
6974

70-
if (requestDecision)
71-
scope.launch {
72-
val userDecision = getUserDecision(cert) // Suspends until user decision is made
73-
onUserDecision(cert, userDecision)
74-
}
75+
// Now the coroutine is suspended, and will be resumed when the user has made a decision using cont.resume()
7576
}
7677

77-
fun onUserDecision(cert: X509Certificate, trusted: Boolean) {
78+
fun resumeOnUserDecision(cert: X509Certificate, trusted: Boolean) {
7879
// save decision
7980
val customCertStore = CustomCertStore.getInstance(context)
8081
if (trusted)

0 commit comments

Comments
 (0)