Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
helper fn
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-olaveide committed Jun 1, 2023
1 parent 5653d67 commit 230758e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/kotlin/no/nav/aap/util/AuthContext.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package no.nav.aap.util

import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ThreadContextElement
import kotlinx.coroutines.async
import org.springframework.web.context.request.RequestAttributes
import org.springframework.web.context.request.RequestContextHolder
import no.nav.aap.api.felles.Fødselsnummer
Expand Down Expand Up @@ -41,4 +44,5 @@ class RequestContextCoroutineContext(private val requestAttributes: RequestAttri
RequestContextHolder.setRequestAttributes(oldState)
} ?: RequestContextHolder.resetRequestAttributes()
}
}
}
fun <T> CoroutineScope.requestContextAwareAsync(block: suspend CoroutineScope.() -> T) = async(Dispatchers.IO + RequestContextCoroutineContext(),block=block)

0 comments on commit 230758e

Please sign in to comment.