kotlinx.coroutines 라이브러리에 대한 의존성을 가지는 코드에서 kotlin.coroutine.coroutineContext 속성 사용 사례를 보고합니다.

kotlin.coroutine.coroutineContextkotlinx.coroutines.CoroutineScope.coroutineContext가 모두 코드에 존재할 수 있는 경우 혼란과 잠재적인 버그를 유발할 수 있습니다.

kotlinx.coroutines 라이브러리는 currentCoroutineContext() 함수를 명시적 충돌이 없더라도 선호해야 할 더 명확한 대안으로 제공합니다.

자세한 내용은 kotlin.coroutine.coroutineContext의 문서를 참조하세요.

예:


  suspend fun getCurrentJob(): Job? {
    return coroutineContext[Job]
  }

빠른 수정을 적용한 후:


  suspend fun getCurrentJob(): Job? {
    return currentCoroutineContext()[Job]
  }