new: integrate a dispatcher provider and dispatch work
This commit is contained in:
@@ -39,9 +39,13 @@ kotlin {
|
||||
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
// Logging
|
||||
// Core modules
|
||||
implementation(projects.core.coroutines)
|
||||
implementation(projects.core.logging)
|
||||
|
||||
// Coroutines
|
||||
implementation(libs.kotlinx.coroutinesCore)
|
||||
|
||||
// DI
|
||||
implementation(project.dependencies.platform(libs.koin.bom))
|
||||
implementation(libs.koin.core)
|
||||
|
||||
+11
-6
@@ -1,20 +1,25 @@
|
||||
package fr.ajaury.gwenedeg.subtitle.data
|
||||
|
||||
import fr.ajaury.gwenedeg.core.coroutines.domain.DispatcherProvider
|
||||
import fr.ajaury.gwenedeg.core.logging.domain.Logger
|
||||
import fr.ajaury.gwenedeg.subtitle.domain.Subtitle
|
||||
import fr.ajaury.gwenedeg.subtitle.domain.SubtitleRepository
|
||||
import fr.ajaury.gwenedeg.subtitle.model.CantGetSubtitleException
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
internal class LrcSubtitleRepository(
|
||||
private val parser: LrcParser,
|
||||
private val dispatcherProvider: DispatcherProvider,
|
||||
private val logger: Logger,
|
||||
) : SubtitleRepository {
|
||||
override suspend fun getSubtitle(content: String): Subtitle =
|
||||
try {
|
||||
parser.parse(content = content)
|
||||
} catch (exception: Exception) {
|
||||
val message = "Failed to load subtitle: $content"
|
||||
logger.error(message = message, throwable = exception)
|
||||
throw CantGetSubtitleException(message)
|
||||
withContext(dispatcherProvider.default) {
|
||||
try {
|
||||
parser.parse(content = content)
|
||||
} catch (exception: Exception) {
|
||||
val message = "Failed to load subtitle: $content"
|
||||
logger.error(message = message, throwable = exception)
|
||||
throw CantGetSubtitleException(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user