How would a higher-order function in a companion o...
# announcements
t
How would a higher-order function in a companion object variable act when being called by multiple threads? Will Kotlin run the function in the caller thread or are objects somehow shared across threads? I need a provided for a thread's namespace and it would be much cleaner to have that provider be a higher-order companion object function but I'm unsure whether it will correctly call the provider from the thread
d
Objects are singletons, across threads. Calling a function makes it execute in the caller's thread. Companion objects are not relevant here at all
t
So I'm not mistaken to assume that a higher-order function in a class's companion object will be called by the thread accessing it?
d
A function, higher order or not, will execute in the thread calling it, yes.
however what that function does with the function passed to it (in case of a higher order function) depends on what the function does...
t
Good to know, thanks
r
@diesieben07 The first rule of tautology club is the first rule of tautology club 🧌
🙃 1