George
02/24/2022, 2:23 PMoverride suspend fun acceptCode(code: String, account: SolidAccount): Unit = coroutineScope {
val codeVerifierDeferred = async { sessionStorage.retrieveCodeVerifier(account) }
val urlDeferred = async { sessionStorage.retrieveUserUrl(account) }
authRequest(codeVerifierDeferred, urlDeferred, code, account)
}
override suspend fun acceptCode(code: String, account: SolidAccount): Unit = coroutineScope {
val codeVerifierDeferred = async { sessionStorage.retrieveCodeVerifier(account) }
val urlDeferred = async { sessionStorage.retrieveUserUrl(account) }
authRequest(codeVerifierDeferred.await(), urlDeferred.await(), code, account)
}
Is there a real difference between these two? Thanks in advance !Matthew Gast
02/24/2022, 2:41 PMauthRequest
, the second block will call authRequest after both sessionStorage.retrieveCodeVerifier
and sessionStorage.retrieveUserUrl
have completed execution. If you are familiar with Java, Future
is an analogue to Deferred
(noting that Future.get
will block while Deferred.async
suspends).George
02/24/2022, 2:45 PM<http://webClient.post|webClient.post>().apply {
val codeVerifier = codeVerifierDeferred.await()
bodyValue(TokenRequestBody(code, codeVerifier).asUrlBody())
val opUrl = urlDeferred.await()
val dpopHeader = generateDPoPHeader(<http://HttpMethod.POST|HttpMethod.POST>, OpUrl(opUrl))
header("DPoP", dpopHeader)
header("content-type", "application/x-www-form-urlencoded")
uri(opUrl.toTokenEndpoint()).exchangeToFlow {
flowOf(it)
}.collect {
My guess is that it would make a difference if was really awaiting much later in the fun?Matthew Gast
02/24/2022, 2:51 PMGeorge
02/24/2022, 3:29 PM