-
Notifications
You must be signed in to change notification settings - Fork 0
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
Create JVM compatible versions of suspend functions. Add annotations to replace names in JVM compiled libraries. #49
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Although I think there's a type issue in the Handler
parameters. If we use this:
Function<SearchInput, Unit> handlerFunction = (SearchInput s) -> {
try {
return semanticSearch.learn(s).get();
} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
};
// JvmClassMappingKt.getKotlinClass
Handler<SearchInput, Unit> writeHandler = new Handler<>(
"learn",
SearchInput.class,
Unit.class,
handlerFunction
);
The classes are not Kclass, but Class (Java). This is an issue in the Function<SearchInput, Unit>
declaration, which I'm trying to solve now 🤔
Could you try this??
@OptIn(DelicateCoroutinesApi::class) | ||
@JvmName("learn") | ||
suspend fun learnCompletableFuture(input: SearchInput) = | ||
GlobalScope.future { learn(input) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a Kotlin expert but I was reading that using CoroutineScope
is more correct and less "delicate" (you can remove the @OptIn annotation):
CoroutineScope(EmptyCoroutineContext).future { learn(input) }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your problem seems to be related to a problem that is not part of the function created. Probably because of the usage of Kotlin functionalities that are not compatible with Java.
Also, CoroutineScope seems to have the same problems as GlobalScope, and it is not recommended to be used by Kotlin's official documentation.
I'm not fully convinced on doing this. If we enable Kotlin Multiplatform, that generates many additional packages in which we could put specific integration code for each platform. Maybe adding the code for the JVM there could help to keep things clean while using idiomatic Kotlin for the core implementation... |
…to replace names in JVM compiled libraries.
42333ee
to
830a9ad
Compare
This PR temporarily solves #47.
It includes fixed methods of
SemanticSearch
class that are compatible with JVM since it generatesCompletableFuture
from theGlobalScope
.This mechanism does two different things:
CompletableFututre
.If someone generates new
suspend
functions that are callable in the API, they would need to follow the same process.A metaprogramming solution like the generation of an annotation processor to generate code on compile time is needed to solve this easily without code repetition. For example, creating a
@JvmCompletableFuture
annotation and a code processor.