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
08/07/2019, 10:39 AM
Objects are singletons, across threads. Calling a function makes it execute in the caller's thread. Companion objects are not relevant here at all
08/07/2019, 10:40 AM
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?
08/07/2019, 10:43 AM
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...
08/07/2019, 10:44 AM
Good to know, thanks
08/07/2019, 1:51 PM
@diesieben07 The first rule of tautology club is the first rule of tautology club :troll: