Skip to content

Commit dab2bfa

Browse files
committed
refactor :: device token 조회 비동기 순차적 처리
1 parent e52f425 commit dab2bfa

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

core/notification/src/main/java/team/aliens/dms/android/core/notification/DeviceTokenManager.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.google.firebase.messaging.FirebaseMessaging
44
import kotlinx.coroutines.CoroutineScope
55
import kotlinx.coroutines.Dispatchers
66
import kotlinx.coroutines.launch
7+
import kotlinx.coroutines.tasks.await
8+
import kotlinx.coroutines.withContext
79
import team.aliens.dms.android.data.notification.repository.NotificationRepository
810
import javax.inject.Inject
911

@@ -15,13 +17,9 @@ class DeviceTokenManager @Inject constructor(
1517
}
1618

1719
suspend fun fetchDeviceToken() {
18-
FirebaseMessaging.getInstance().token.addOnCompleteListener { task ->
19-
if (!task.isSuccessful) {
20-
// TODO: Handle error
21-
}
22-
CoroutineScope(Dispatchers.IO).launch {
23-
notificationRepository.saveDeviceToken(deviceToken = task.result)
24-
}
20+
val token = FirebaseMessaging.getInstance().token.await()
21+
withContext(Dispatchers.IO) {
22+
notificationRepository.saveDeviceToken(deviceToken = token)
2523
}
2624
}
2725
}

0 commit comments

Comments
 (0)