kotlin协程分享

上周在公司做了个分享,转成图片发吧


coroutine.001.jpeg
coroutine.002.jpeg
coroutine.003.jpeg
coroutine.004.jpeg
coroutine.005.jpeg
coroutine.006.jpeg
coroutine.007.jpeg
coroutine.008.jpeg
coroutine.009.jpeg
coroutine.010.jpeg
coroutine.011.jpeg
coroutine.012.jpeg
coroutine.013.jpeg
coroutine.014.jpeg
suspend fun displayMyMultipleChoiceDialog(): MyDialogResult {
    lateinit var result: Continuation<MyDialogResult>
    AlertDialog.Builder(this)
        .setTitle(...string resource...)
    .setMessage(...string resource...)
    .setPositiveButton(...RETRY string..., { dialogInterface: DialogInterface, _: Int ->
        dialogInterface.dismiss()
        result.resume(MyDialogResult.RETRY)
    })
    .setNegativeButton(...CANCEL string..., { dialogInterface: DialogInterface, _: Int ->
        dialogInterface.dismiss()
        result.resume(MyDialogResult.CANCEL)
    })
    .setOnCancelListener {
        result.resume(MyDialogResult.CANCEL)
    }
    .create()
    .show()

    return suspendCoroutine {continuation -> result = continuation}
}

fun myPresenterMethod() {
    launchAsync {
        when (view.displayMyMultipleChoiceDialog()) {
            RETRY -> ...do something...
            CANCEL -> ...do something else...
        }
    }
}

btw最近准备看一下redex~ 希望能尽快出专题

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。