Skip to content

Feature: Execution Transformers #1

Description

@ItsDoot

Basically what I am looking for is a convenient way to wrap a function call given some annotations on the function.

A good starting point:

typealias ExecutionContext = MutableMap<String, Any?>

interface ExecutionTransformer {
    @Throws(CommandException::class)
    fun transform(src: CommandSource, context: ExecutionContext, next: () -> Unit)
}

My primary usecase: wrapping function calls in Exposed transaction blocks, to reduce redundancy.

import org.jetbrains.exposed.sql.transactions.transaction

annotation class Transactional

object TransactionExecutionTransformer : ExecutionTransformer {
    override fun transform(src: CommandSource, context: ExecutionContext, next: () -> Unit) {
        transaction {
            next()
        }
    }
}

@Transactional
@Command("mycmd")
fun mycmd(@Source src: CommandSource) {
    // we can do things with a table since we're in a transaction
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions