Skip to content

Commit

Permalink
fix: suspendCoroutine 사용 (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Oct 2, 2024
1 parent 5ece48e commit cfd93a1
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import com.kakao.sdk.auth.model.OAuthToken
import com.kakao.sdk.common.model.ClientError
import com.kakao.sdk.common.model.ClientErrorCause
import com.kakao.sdk.user.UserApiClient
import kotlinx.coroutines.suspendCancellableCoroutine
import javax.inject.Inject
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

class KakaoStrategy @Inject constructor() : BaseStrategy() {
private val tag = this.javaClass.name
Expand Down Expand Up @@ -37,19 +37,14 @@ class KakaoStrategy @Inject constructor() : BaseStrategy() {
* @param context Context
* @return [OAuthToken] 로그인 성공 시 발급되는 토큰
*/
private suspend fun loginWithKakaoTalk(context: Context): OAuthToken = suspendCancellableCoroutine { continuation ->
private suspend fun loginWithKakaoTalk(context: Context): OAuthToken = suspendCoroutine { continuation ->
UserApiClient.instance.loginWithKakaoTalk(context) { token, error ->
when {
error != null -> continuation.resumeWithException(error)
token != null -> continuation.resume(token)
else -> continuation.resumeWithException(IllegalStateException("Unexpected error during KakaoTalk login"))
}
}

continuation.invokeOnCancellation {
Log.d(tag, "loginWithKakaoTalk: invokeOnCancellation")
// TODO LOGGING
}
}

/**
Expand All @@ -60,18 +55,13 @@ class KakaoStrategy @Inject constructor() : BaseStrategy() {
* @param context Context
* @return [OAuthToken] 로그인 성공 시 발급되는 토큰
*/
private suspend fun loginWithKakaoAccount(context: Context): OAuthToken = suspendCancellableCoroutine { continuation ->
private suspend fun loginWithKakaoAccount(context: Context): OAuthToken = suspendCoroutine { continuation ->
UserApiClient.instance.loginWithKakaoAccount(context) { token, error ->
when {
error != null -> continuation.resumeWithException(error)
token != null -> continuation.resume(token)
else -> continuation.resumeWithException(IllegalStateException("Unexpected error during KakaoAccount login"))
}
}

continuation.invokeOnCancellation {
Log.d(tag, "loginWithKakaoAccount: invokeOnCancellation")
// TODO LOGGING
}
}
}

0 comments on commit cfd93a1

Please sign in to comment.