在我的 Android Kotlin 项目中,我在协程中调用了一个 webservice(myWebservice只是一个管理 webservice 调用的自定义类):
fun searchForItems(userInput: String)
{
CoroutineScope(Dispatchers.IO + Job()).launch {
val listOfItems = myWebService.call(userInput)
}
}
Run Code Online (Sandbox Code Playgroud)
每次用户在一个字符中键入一个字符时都会调用该方法 EditText,因此该应用程序会调用 Web 服务,该服务会返回与其请求匹配的项目列表。但我想优化它。
假设用户键入单词:“apple”。为了尽量减少 webservice 调用的次数,这是我想要实现的:
实现这一目标的最佳实践是什么?或者有没有更好的方法来减少网络服务调用的次数?
谢谢。