Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

전남대 Android_장수민_4주차 과제(Step2)(재제출) #105

Open
wants to merge 14 commits into
base: sumintnals
Choose a base branch
from

Conversation

sumintnals
Copy link

과제 재제출 입니다!!

참고사항

  • 테스트 코드 외 피드백 주신 부분은, re-request 할 때 수정해두었습니다!!

변경사항

  • 테스트 코드 추가하였습니다!
    라이브데이터를 테스트 코드에서 사용할 때 필요한 코드가 있다는 것을 이번에 알게 되었습니다.
fun <T> LiveData<T>.getOrAwaitValue(
    time: Long = 2,
    timeUnit: TimeUnit = TimeUnit.SECONDS
): T {
    var data: T? = null
    val latch = CountDownLatch(1)
    val observer = object : Observer<T> {
        override fun onChanged(value: T) {
            data = value
            latch.countDown()
            [email protected](this)
        }
    }

    this.observeForever(observer)

    if (!latch.await(time, timeUnit)) {
        throw TimeoutException("LiveData value was never set.")
    }

    @Suppress("UNCHECKED_CAST")
    return data as T
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant