|
@@ -19,7 +19,7 @@ var scope: CoroutineScope? = null
|
|
|
|
|
|
et_input.debounce().listen(this) {
|
|
|
scope?.cancel() // 发起新的请求前取消旧的请求, 避免旧数据覆盖新数据
|
|
|
- scope = scopeNetLife { // 保存旧的请求到一个变量中
|
|
|
+ scope = scopeNetLife { // 保存旧的请求到一个变量中, scopeNetLife其函数决定网络请求生命周期
|
|
|
tv_request_content.text = "请求中"
|
|
|
val data = Get<String>("http://api.k780.com/?app=life.time&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json",
|
|
|
absolutePath = true).await()
|
|
@@ -31,4 +31,9 @@ et_input.debounce().listen(this) {
|
|
|
如果想要设置自己的节流阀超时时间请指定参数
|
|
|
```kotlin
|
|
|
fun EditText.debounce(timeoutMillis: Long = 800)
|
|
|
-```
|
|
|
+```
|
|
|
+
|
|
|
+## 生命周期
|
|
|
+其生命周期依然遵守[网络请求作用域函数scope*](scope.md#_2)
|
|
|
+
|
|
|
+例如示例中使用的`scopeNetLife`就会在Activity或Fragment关闭时自动取消网络请求
|