scopeNetLife

fun LifecycleOwner.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope

该函数比scopeNet多了自动取消作用域功能

该作用域生命周期跟随LifecycleOwner. 比如传入Activity会默认在FragmentActivity.onDestroy时取消网络请求.

Parameters

<receiver>

可传入FragmentActivity/AppCompatActivity, 或者其他的实现了LifecycleOwner的类

lifeEvent

指定LifecycleOwner处于生命周期下取消网络请求/作用域

dispatcher

调度器, 默认运行在Dispatchers.Main即主线程下

fun Fragment.scopeNetLife(lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_STOP, dispatcher: CoroutineDispatcher = Dispatchers.Main, block: suspend CoroutineScope.() -> Unit): NetCoroutineScope

和上述函数功能相同, 只是接受者为Fragment

Fragment应当在Lifecycle.Event.ON_STOP时就取消作用域, 避免Fragment.onDestroyView导致引用空视图