Skip to content

Commit

Permalink
Merge pull request #2 from makeevrserg/suspend-usecase
Browse files Browse the repository at this point in the history
Suspend usecase
  • Loading branch information
makeevrserg authored Oct 29, 2023
2 parents c654077 + 43fb0f2 commit 37419ba
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Gradle
```kotlin
implementation("ru.astrainteractive.klibs:mikro-core:<version>")
implementation("ru.astrainteractive.klibs:mikro-platform:<version>")
implementation("ru.astrainteractive.klibs:mikro-extensions:<version>")
implementation("ru.astrainteractive.klibs:mikro-locale:<version>")
implementation("ru.astrainteractive.klibs:mikro-validation:<version>")
```

Version catalogs
Expand All @@ -23,6 +26,9 @@ klibs-mikro = "<latest-version>"
[libraries]
klibs-mikro-core = { module = "ru.astrainteractive.klibs:mikro-core", version.ref = "klibs-mikro" }
klibs-mikro-platform = { module = "ru.astrainteractive.klibs:mikro-platform", version.ref = "klibs-mikro" }
klibs-mikro-extensions = { module = "ru.astrainteractive.klibs:mikro-extensions", version.ref = "klibs-mikro" }
klibs-mikro-locale = { module = "ru.astrainteractive.klibs:mikro-locale", version.ref = "klibs-mikro" }
klibs-mikro-validation = { module = "ru.astrainteractive.klibs:mikro-validation", version.ref = "klibs-mikro" }
```

### Platform
Expand Down Expand Up @@ -85,17 +91,17 @@ class StringMapper : Mapper<String, Int> {

```kotlin
// Use simple UseCase
class IntUseCase : UseCase.Simple<Int> {
override suspend fun invoke(): Int {
class IntUseCase : UseCase.Suspended.Simple<Int> {
override suspend operator fun invoke(): Int {
return 10
}
}

// Or Parametrized
class MultiplyUseCase : UseCase.Parametrized<MultiplyUseCase.Param, Int> {
// Or Parametrized and blocking
class MultiplyUseCase : UseCase.Blocking.Parametrized<MultiplyUseCase.Param, Int> {
class Param(val value: Int, val multiplyBy: Int)

override suspend fun invoke(input: Param): Int {
override operator fun invoke(input: Param): Int {
return input.value * input.multiplyBy
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ makeevrserg.java.ktarget=17
# Project
makeevrserg.project.name=MiKro
makeevrserg.project.group=ru.astrainteractive.klibs
makeevrserg.project.version.string=1.3.0
makeevrserg.project.version.string=1.4.0
makeevrserg.project.description=Kotlin Multiplatform library with useful code
makeevrserg.project.developers=makeevrserg|Makeev Roman|[email protected]
makeevrserg.project.url=https://github.com/makeevrserg/kstorage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@ package ru.astrainteractive.klibs.mikro.core.domain
/**
* UseCase from CleanArchitecture
*/
interface UseCase<out Output> {
interface Parametrized<in Input, out Output> : UseCase<Output> {
interface UseCase<in Input, out Output> {
/**
* [Suspended] is use to call suspended methods
*/
interface Suspended<in Input, out Output> : UseCase<Input, Output> {
suspend operator fun invoke(input: Input): Output

interface Simple<out Output> : Suspended<Unit, Output> {
suspend operator fun invoke(): Output = invoke(Unit)
}
}

interface Simple<out Output> : UseCase<Output> {
suspend operator fun invoke(): Output
/**
* [Blocking] is used to call blocking methods without coroutines
*/
interface Blocking<in Input, out Output> : UseCase<Input, Output> {
operator fun invoke(input: Input): Output

interface Simple<out Output> : Blocking<Unit, Output> {
operator fun invoke(): Output = invoke(Unit)
}
}
}

0 comments on commit 37419ba

Please sign in to comment.