In my application I need to perform Network calls using a specific framework. Because every network call need to be performed on the separate thread I would like to have one function which start new Thread perform a call and return an object. To do so I tried to use HigherOrderFunctions, but I didn't find until now how to declare function as an argument which take a variable number of arguments.
To give you an idea I would like to have something like this:
fun Client.performNetworkCall(calledFunction:(vararg Object)->Object):Object{
Thread(Runnable {
calledFunction
}).start()
//return function results
}
But it seems to impossible to declare such function. Is it possible in Kotlin? I would like avoid creating every time new thread in my code when I need to perform a network call. So that I can write something like this
client.performNetworkCall{ bean.createNewUser(User("","","Gosia","gosiak@gmail.com","pass"))}
bean is object of my interface which hava a function createNewUser. Function createNewUser is implement on server and will return some result after execution.
If what I want to do is not possible using higher order function, can you give me a hint what else can I do get something like I described above?