Skip to content

Commit

Permalink
Run execution on default thread, allow destroying of scripting engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Waboodoo committed Dec 29, 2024
1 parent 8de5ae9 commit aa6ff8f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -172,13 +173,15 @@ class Execution(
}
logException(e)
} finally {
scriptExecutor.destroy()
tryOrLog {
cacheFilesCleanupStarter()
historyCleanUpStarter()
executionSchedulerStarter()
}
}
}
.flowOn(Dispatchers.Default)
.onEach { status ->
if (status is ExecutionStatus.WithResult) {
sessionMonitor.onResult(status.result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ constructor(
.also {
registerActionAliases(it, actionFactory.getAliases())
registerAbort(it)
destroyer = it::destroy
}
}
private var destroyer: (() -> Unit)? = null

private val cleanupHandler = CleanupHandler()

Expand Down Expand Up @@ -262,6 +264,10 @@ constructor(
)
}

fun destroy() {
destroyer?.invoke()
}

companion object {

private const val NO_RESULT = "[[[no result]]]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ interface ScriptingEngine {
fun registerListOfObjects(name: String, list: List<JsObject>)

fun buildJsObject(builder: JsObjectBuilder.() -> Unit): JsObject

fun destroy()
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ internal class LiquidCoreScriptingEngine : ScriptingEngine {
internal fun JsObject.toJSObject(): JSObject =
(this as LiquidCoreJsObject).toJSObject()

override fun destroy() {
// nothing to do, LiquidCore doesn't have a shutdown function
}

companion object {
private const val READ_ONLY =
JSContext.JSPropertyAttributeReadOnly or JSContext.JSPropertyAttributeDontDelete
Expand Down

0 comments on commit aa6ff8f

Please sign in to comment.