package com.quyunshuo.androidbaseframemvvm.base.mvvm.m

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

/**
 * 仓库层 Repository 基类
 *
 * @author Qu Yunshuo
 * @since 8/27/20
 */
open class BaseRepository {

    /**
     * 发起请求封装
     * 该方法将flow的执行切换至IO线程
     *
     * @param requestBlock 请求的整体逻辑
     * @return Flow<T> @BuilderInference block: suspend FlowCollector<T>.() -> Unit
     */
    protected fun <T> request(
        requestBlock: suspend FlowCollector<T>.() -> Unit
    ): Flow<T> {
        return flow(block = requestBlock).flowOn(Dispatchers.IO)
    }


}