Skip to content

Commit

Permalink
[minor] initial Scheduler POC
Browse files Browse the repository at this point in the history
Update to stable kudzu, ballast
  • Loading branch information
cjbrooks12 committed Jan 26, 2024
1 parent 37ff255 commit 3db01a7
Show file tree
Hide file tree
Showing 107 changed files with 5,248 additions and 412 deletions.
20 changes: 20 additions & 0 deletions ballast-api/api/android/ballast-api.api
Expand Up @@ -391,18 +391,21 @@ public final class com/copperleaf/ballast/Queued$HandleInput : com/copperleaf/ba
public fun <init> (Lkotlinx/coroutines/CompletableDeferred;Ljava/lang/Object;)V
public fun getDeferred ()Lkotlinx/coroutines/CompletableDeferred;
public final fun getInput ()Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
}

public final class com/copperleaf/ballast/Queued$RestoreState : com/copperleaf/ballast/Queued {
public fun <init> (Lkotlinx/coroutines/CompletableDeferred;Ljava/lang/Object;)V
public fun getDeferred ()Lkotlinx/coroutines/CompletableDeferred;
public final fun getState ()Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
}

public final class com/copperleaf/ballast/Queued$ShutDownGracefully : com/copperleaf/ballast/Queued {
public synthetic fun <init> (Lkotlinx/coroutines/CompletableDeferred;JLkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun getDeferred ()Lkotlinx/coroutines/CompletableDeferred;
public final fun getGracePeriod-UwyO8pc ()J
public fun toString ()Ljava/lang/String;
}

public abstract interface class com/copperleaf/ballast/SideJobScope : kotlinx/coroutines/CoroutineScope {
Expand Down Expand Up @@ -597,6 +600,23 @@ public final class com/copperleaf/ballast/internal/BallastViewModelImpl : com/co
public fun trySend-JP2dKIU (Ljava/lang/Object;)Ljava/lang/Object;
}

public abstract interface class com/copperleaf/ballast/internal/RestartableJob : kotlinx/coroutines/Job {
public abstract fun restart (Ljava/lang/Object;)V
}

public final class com/copperleaf/ballast/internal/RestartableJob$DefaultImpls {
public static synthetic fun cancel (Lcom/copperleaf/ballast/internal/RestartableJob;)V
public static fun fold (Lcom/copperleaf/ballast/internal/RestartableJob;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public static fun get (Lcom/copperleaf/ballast/internal/RestartableJob;Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element;
public static fun minusKey (Lcom/copperleaf/ballast/internal/RestartableJob;Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext;
public static fun plus (Lcom/copperleaf/ballast/internal/RestartableJob;Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
public static fun plus (Lcom/copperleaf/ballast/internal/RestartableJob;Lkotlinx/coroutines/Job;)Lkotlinx/coroutines/Job;
}

public final class com/copperleaf/ballast/internal/RestartableJobKt {
public static final fun restartableJob (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function3;)Lcom/copperleaf/ballast/internal/RestartableJob;
}

public abstract interface class com/copperleaf/ballast/internal/Status {
public abstract fun checkCanClear ()V
public abstract fun checkCanShutDown ()V
Expand Down
20 changes: 20 additions & 0 deletions ballast-api/api/jvm/ballast-api.api
Expand Up @@ -391,18 +391,21 @@ public final class com/copperleaf/ballast/Queued$HandleInput : com/copperleaf/ba
public fun <init> (Lkotlinx/coroutines/CompletableDeferred;Ljava/lang/Object;)V
public fun getDeferred ()Lkotlinx/coroutines/CompletableDeferred;
public final fun getInput ()Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
}

public final class com/copperleaf/ballast/Queued$RestoreState : com/copperleaf/ballast/Queued {
public fun <init> (Lkotlinx/coroutines/CompletableDeferred;Ljava/lang/Object;)V
public fun getDeferred ()Lkotlinx/coroutines/CompletableDeferred;
public final fun getState ()Ljava/lang/Object;
public fun toString ()Ljava/lang/String;
}

public final class com/copperleaf/ballast/Queued$ShutDownGracefully : com/copperleaf/ballast/Queued {
public synthetic fun <init> (Lkotlinx/coroutines/CompletableDeferred;JLkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun getDeferred ()Lkotlinx/coroutines/CompletableDeferred;
public final fun getGracePeriod-UwyO8pc ()J
public fun toString ()Ljava/lang/String;
}

public abstract interface class com/copperleaf/ballast/SideJobScope : kotlinx/coroutines/CoroutineScope {
Expand Down Expand Up @@ -597,6 +600,23 @@ public final class com/copperleaf/ballast/internal/BallastViewModelImpl : com/co
public fun trySend-JP2dKIU (Ljava/lang/Object;)Ljava/lang/Object;
}

public abstract interface class com/copperleaf/ballast/internal/RestartableJob : kotlinx/coroutines/Job {
public abstract fun restart (Ljava/lang/Object;)V
}

public final class com/copperleaf/ballast/internal/RestartableJob$DefaultImpls {
public static synthetic fun cancel (Lcom/copperleaf/ballast/internal/RestartableJob;)V
public static fun fold (Lcom/copperleaf/ballast/internal/RestartableJob;Ljava/lang/Object;Lkotlin/jvm/functions/Function2;)Ljava/lang/Object;
public static fun get (Lcom/copperleaf/ballast/internal/RestartableJob;Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext$Element;
public static fun minusKey (Lcom/copperleaf/ballast/internal/RestartableJob;Lkotlin/coroutines/CoroutineContext$Key;)Lkotlin/coroutines/CoroutineContext;
public static fun plus (Lcom/copperleaf/ballast/internal/RestartableJob;Lkotlin/coroutines/CoroutineContext;)Lkotlin/coroutines/CoroutineContext;
public static fun plus (Lcom/copperleaf/ballast/internal/RestartableJob;Lkotlinx/coroutines/Job;)Lkotlinx/coroutines/Job;
}

public final class com/copperleaf/ballast/internal/RestartableJobKt {
public static final fun restartableJob (Lkotlinx/coroutines/CoroutineScope;Lkotlin/jvm/functions/Function3;)Lcom/copperleaf/ballast/internal/RestartableJob;
}

public abstract interface class com/copperleaf/ballast/internal/Status {
public abstract fun checkCanClear ()V
public abstract fun checkCanShutDown ()V
Expand Down
18 changes: 15 additions & 3 deletions ballast-api/src/commonMain/kotlin/com/copperleaf/ballast/Queued.kt
Expand Up @@ -19,15 +19,23 @@ public sealed class Queued<Inputs : Any, Events : Any, State : Any> {
public class RestoreState<Inputs : Any, Events : Any, State : Any>(
public override val deferred: CompletableDeferred<Unit>?,
public val state: State,
) : Queued<Inputs, Events, State>()
) : Queued<Inputs, Events, State>() {
override fun toString(): String {
return "RestoreState(state=$state)"
}
}

/**
* A request to handle an Input by sending it to the [InputHandler].
*/
public class HandleInput<Inputs : Any, Events : Any, State : Any>(
public override val deferred: CompletableDeferred<Unit>?,
public val input: Inputs,
) : Queued<Inputs, Events, State>()
) : Queued<Inputs, Events, State>() {
override fun toString(): String {
return "HandleInput(input=$input)"
}
}

/**
* A request to gracefully shut down the ViewModel. This will attempt to let it finish processing any Inputs
Expand All @@ -42,5 +50,9 @@ public sealed class Queued<Inputs : Any, Events : Any, State : Any> {
public class ShutDownGracefully<Inputs : Any, Events : Any, State : Any>(
public override val deferred: CompletableDeferred<Unit>?,
public val gracePeriod: Duration,
) : Queued<Inputs, Events, State>()
) : Queued<Inputs, Events, State>() {
override fun toString(): String {
return "ShutDownGracefully(gracePeriod=$gracePeriod)"
}
}
}
@@ -0,0 +1,26 @@
package com.copperleaf.ballast.internal

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.consumeAsFlow
import kotlinx.coroutines.launch

public interface RestartableJob<T> : Job {
public fun restart(context: T)
}

public fun <T> CoroutineScope.restartableJob(
block: suspend CoroutineScope.(T) -> Unit,
): RestartableJob<T> {
val channel = Channel<T>(Channel.CONFLATED)
val job = launch {
channel.consumeAsFlow().collectLatest { block(it) }
}
return object : RestartableJob<T>, Job by job {
override fun restart(context: T) {
channel.trySend(context)
}
}
}

0 comments on commit 3db01a7

Please sign in to comment.