-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from team-JMT/feat/jmtException_sandbox
JmtException 실험용 코드(커스텀 Exeption)
- Loading branch information
Showing
11 changed files
with
109 additions
and
18 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
data/src/main/java/org/gdsc/data/datasource/LoginDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
domain/src/main/java/org/gdsc/domain/exception/JmtException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.gdsc.domain.exception | ||
|
||
import org.gdsc.domain.Empty | ||
|
||
sealed class JmtException( | ||
message: String = String.Empty | ||
) : Exception(message) { | ||
|
||
data class NetworkException(override val message: String = "네트워크 연결을 확인해주세요.") : JmtException() | ||
data class ServerException(override val message: String = "서버에 문제가 발생했습니다.") : JmtException() | ||
data class NoneDataException(override val message: String = "데이터가 없습니다.") : JmtException() | ||
data class UnKnownException(override val message: String = "알 수 없는 에러입니다.") : JmtException() | ||
data class GeneralException(override val message: String) : JmtException() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
presentation/src/main/java/org/gdsc/presentation/utils/EventFlow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.gdsc.presentation.utils | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.FlowCollector | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import org.gdsc.presentation.utils.EventFlow.Companion.DEFAULT_REPLAY | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
interface EventFlow<out T> : Flow<T> { | ||
|
||
companion object { | ||
const val DEFAULT_REPLAY = 2 | ||
} | ||
} | ||
|
||
interface MutableEventFlow<T> : EventFlow<T>, FlowCollector<T> | ||
|
||
private class EventFlowSlot<T>(val value: T) { | ||
|
||
private val consumed = AtomicBoolean(false) | ||
|
||
fun markConsumed() = consumed.getAndSet(true) | ||
} | ||
|
||
private class EventFlowImpl<T>(replay: Int) : MutableEventFlow<T> { | ||
|
||
private val flow: MutableSharedFlow<EventFlowSlot<T>> = MutableSharedFlow(replay) | ||
|
||
override suspend fun collect(collector: FlowCollector<T>) = | ||
flow.collect { slot -> | ||
if (slot.markConsumed().not()) { | ||
collector.emit(slot.value) | ||
} | ||
} | ||
|
||
override suspend fun emit(value: T) { | ||
flow.emit(EventFlowSlot(value)) | ||
} | ||
} | ||
|
||
private class ReadOnlyEventFlow<T>(flow: EventFlow<T>) : EventFlow<T> by flow | ||
|
||
fun <T> MutableEventFlow(replay: Int = DEFAULT_REPLAY): MutableEventFlow<T> = EventFlowImpl(replay) | ||
|
||
fun <T> MutableEventFlow<T>.asEventFlow(): EventFlow<T> = ReadOnlyEventFlow(this) |