函数无法返回带有协程块的项目

I am retrieving a record from a Room database using Coroutines because it has to run in a background thread. I want to return the result through the function.

class LessonRepository(val app: Application) {

    private val courseDao = MyDatabase.getDatabase(app).courseDao()
}

    fun getCourseData(): Course {

        var course: Course

        CoroutineScope(Dispatchers.IO).launch {
            course = courseDao.getCourse(globalSelectedCourse)
        }
        return course
    }

视图模型

class LessonViewModel(app: Application): AndroidViewModel(app) {

    private val lessonDataRepository = LessonRepository(app)
    val lessonData = lessonDataRepository.lessonData
    val selectedLesson = MutableLiveData<Lesson>()

    fun getCourseData() : Course {
        return lessonDataRepository.getCourseData()
    }
}

我想在片段中使用返回值:

class DetailFragment : Fragment(), LessonRecyclerAdapter.LessonItemListener {
.
.
.
        viewModel = ViewModelProvider(this).get(LessonViewModel::class.java)

        val course = viewModel.getCourseData()
.
.
.
    }

However, Android Studio is giving me an error indicator in the return statement return course that course must be initialized. How can i successfuly return the value of course?

-更新:-

我正在尝试获取该记录的值,并将其用于片段中,如下所示:

val course = viewModel.viewModelScope.launch { viewModel.getCourseData() }

textViewName.text = course.Name
textViewInstructor.text = course.instructor