上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 169 下一页
摘要: 一,代码: //处理按钮点击事件: 异常位于catch上游 binding.button1.setOnClickListener { runBlocking { val flow = flow { emit(1) emit(2) throw IllegalStateException() emit( 阅读全文
posted @ 2025-08-02 15:00 刘宏缔的架构森林 阅读(10) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件 binding.button1.setOnClickListener { runBlocking { // Flow转List flowOf(1, 2, 3, 4, 5) .toList() .filter { it > 2 } .map { it * 2 } .t 阅读全文
posted @ 2025-08-02 15:00 刘宏缔的架构森林 阅读(14) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件 binding.button2.setOnClickListener { runBlocking { flowOf(1, 2, 3, 4, 5) .take(2) // 注意这里 .filter { println("filter: $it") it > 2 } . 阅读全文
posted @ 2025-08-02 15:00 刘宏缔的架构森林 阅读(15) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件 binding.button1.setOnClickListener { runBlocking { flow { // 上游,发源地 emit(1) // 挂起函数 emit(2) emit(3) emit(4) emit(5) }.filter { printl 阅读全文
posted @ 2025-08-02 15:00 刘宏缔的架构森林 阅读(7) 评论(0) 推荐(0)
摘要: 一,代码: 例子:需要访问缓存和网络来获取数据,如果从缓存先返回,先更新ui,从网络获取数据后再更新一次,如果从网络先返回,更新ui 数据类: data class Product( //id val productId: String, //价格 val price: Double, // 是不是 阅读全文
posted @ 2025-08-02 15:00 刘宏缔的架构森林 阅读(8) 评论(0) 推荐(0)
摘要: 一,代码: 自定义dispatcher: 自定义了两个dispatcher val myCustomDispatcher1 = newSingleThreadContext("MyCustomThread1") val myCustomDispatcher2= Executors.newSingle 阅读全文
posted @ 2025-08-02 15:00 刘宏缔的架构森林 阅读(46) 评论(0) 推荐(0)
摘要: 一,代码: 函数: //得到用户信息,演示指定dispatcher suspend fun getUserInfo(): String { logX("Before IO Context.") withContext(Dispatchers.IO) { logX("In IO Context.") 阅读全文
posted @ 2025-08-02 14:59 刘宏缔的架构森林 阅读(31) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件 binding.button2.setOnClickListener { runBlocking { suspend fun getResult1(): String { delay(3000L) // 模拟耗时操作 return "Result1" } suspe 阅读全文
posted @ 2025-08-02 14:59 刘宏缔的架构森林 阅读(6) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件 binding.button1.setOnClickListener { runBlocking { suspend fun download() { // 模拟下载任务 delay(1000L) } println("得到job") val job = launc 阅读全文
posted @ 2025-08-02 14:59 刘宏缔的架构森林 阅读(14) 评论(0) 推荐(0)
摘要: 一,代码: //处理按钮点击事件 binding.button2.setOnClickListener { runBlocking(Dispatchers.IO) { repeat(3) { index -> launch { //println() repeat(3) { println("第"+ 阅读全文
posted @ 2025-08-02 14:59 刘宏缔的架构森林 阅读(33) 评论(0) 推荐(0)
上一页 1 ··· 14 15 16 17 18 19 20 21 22 ··· 169 下一页