Hello In the `defaultRequest` plugin, I need to re...
# ktor
d
Hello In the
defaultRequest
plugin, I need to retrieve a value that's protected by a Mutex.
Copy code
defaultRequest {
                url(baseUrl)

                // headerBuilder needs to be called in suspend function
                headerBuilder().forEach { (key, value) ->
                    header(key, value)
                }
            }
However, the builder doesn't support suspend context. Instead of Mutex, there is the
lock
but that will block the thread and I don't want to have performance issue. I'm in a multiplatform context so I don't have the Runblocking function. Do you have a solution about that? 🤔
a
Does the
headerBuilder()
return different values at different times?
d
No, but one value is retrieved by interacting with a Mutex
a
Can you retrieve the headers once and use the result for each request (in the
url
method) ?
d
Hum no because the token (who is protected by mutex) is renew every 2hours So the header is build for each request
a
So the thread will be noticeably blocked only once per 2 hours if the lock mechanism will be used or I misunderstand the situation?
d
Exactly, or when the user force a new login
So, the mutex is "rarely" blocked, but ..
A concurrency problem can be present and that's annoying 😕