Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usage of Kotlin's Function2 in the spring boot java app #31

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion inngest-core/src/main/kotlin/com/inngest/Function.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.inngest

import com.beust.klaxon.Json
import java.util.function.BiFunction

// IDEA: Use data classes
data class FunctionOptions(
Expand Down Expand Up @@ -104,8 +105,13 @@ interface Function {
// TODO: make this implement the Function interface
open class InngestFunction(
val config: FunctionOptions,
val handler: (ctx: FunctionContext, step: Step) -> kotlin.Any?,
val handler: (ctx: FunctionContext, step: Step) -> Any?,
) {
constructor(config: FunctionOptions, handler: BiFunction<FunctionContext, Step, out Any>, a: Int) : this(
config,
handler.toKotlin(),
)

fun id() = config.id

// TODO - Validate options and trigger
Expand Down
5 changes: 5 additions & 0 deletions inngest-core/src/main/kotlin/com/inngest/LambdaHelpers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.inngest

import java.util.function.BiFunction

internal fun <A, B, C> BiFunction<A, B, C>.toKotlin(): (A, B) -> C = { a, b -> this.apply(a, b) }
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

import com.inngest.*;
import com.inngest.springboot.InngestConfiguration;
import kotlin.jvm.functions.Function2;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.LinkedHashMap;
import java.time.Duration;
import java.util.HashMap;
import java.util.function.BiFunction;

@Configuration
public class DemoConfiguration extends InngestConfiguration {
Expand All @@ -21,7 +20,7 @@ public HashMap<String, InngestFunction> functions() {
FunctionTrigger[] triggers = {fnTrigger};
FunctionOptions fnConfig = new FunctionOptions("fn-id-slug", "My function!", triggers);

Function2<FunctionContext, Step, HashMap<String, String>> handler = (ctx, step) -> {
BiFunction<FunctionContext, Step, HashMap<String, String>> handler = (ctx, step) -> {
int x = 10;

System.out.println("-> handler called " + ctx.getEvent().getName());
Expand Down Expand Up @@ -62,14 +61,14 @@ public HashMap<String, InngestFunction> functions() {
"Follow up function!",
new FunctionTrigger[]{followupFnTrigger}
);
Function2<FunctionContext, Step, LinkedHashMap<String, Object>> followupHandler = (ctx, step) -> {
BiFunction<FunctionContext, Step, LinkedHashMap<String, Object>> followupHandler = (ctx, step) -> {
System.out.println("-> follow up handler called " + ctx.getEvent().getName());
return ctx.getEvent().getData();
};

HashMap<String, InngestFunction> functions = new HashMap<>();
functions.put("fn-id-slug", new InngestFunction(fnConfig, handler));
functions.put("fn-follow-up", new InngestFunction(followupFnConfig, followupHandler));
functions.put("fn-id-slug", new InngestFunction(fnConfig, handler,1));
functions.put("fn-follow-up", new InngestFunction(followupFnConfig, followupHandler,2));

return functions;
}
Expand Down
Loading