Skip to content

Commit

Permalink
Create core interfaces for application
Browse files Browse the repository at this point in the history
Signed-off-by: Yurii Surzhykov <yurii.surzhykov@nortekcontrol.com>
  • Loading branch information
Yurii Surzhykov committed May 23, 2024
1 parent 96dd7da commit 5897c9e
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 2 deletions.
5 changes: 4 additions & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
plugins {
id("java-library")
alias(libs.plugins.jetbrains.kotlin.jvm)
}

java {
sourceCompatibility = JavaVersion.VERSION_19
targetCompatibility = JavaVersion.VERSION_19
}

dependencies {
implementation(libs.kotlinx.coroutines.core)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.github.yuriisurzhykov.purs.core

class Core {
interface Clear {

fun clear()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.github.yuriisurzhykov.purs.core

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

interface Dispatchers {

fun launchUi(scope: CoroutineScope, block: suspend CoroutineScope.() -> Unit): Job
fun launchBackground(scope: CoroutineScope, block: suspend CoroutineScope.() -> Unit): Job
suspend fun switchToUi(block: suspend CoroutineScope.() -> Unit)

abstract class Abstract(
private val uiScope: CoroutineDispatcher,
private val backgroundScope: CoroutineDispatcher
) : Dispatchers {
override fun launchUi(
scope: CoroutineScope,
block: suspend CoroutineScope.() -> Unit
): Job = scope.launch(uiScope, block = block)

override fun launchBackground(
scope: CoroutineScope,
block: suspend CoroutineScope.() -> Unit
): Job = scope.launch(backgroundScope, block = block)

override suspend fun switchToUi(block: suspend CoroutineScope.() -> Unit) =
withContext(uiScope, block)
}

class Base : Abstract(
uiScope = kotlinx.coroutines.Dispatchers.Main,
backgroundScope = kotlinx.coroutines.Dispatchers.Default
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.yuriisurzhykov.purs.core

interface Mapper<S, R> {

fun map(source: S): R

interface Unit<T> : Mapper<T, Unit<T>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.yuriisurzhykov.purs.core

interface Read<T> {

fun read(): T
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.yuriisurzhykov.purs.core

interface Save<T> {

fun save(data: T)
}

0 comments on commit 5897c9e

Please sign in to comment.