-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1092 from mariofusco/no-bloking-jlama
Prevent Jlama inference to block vertx event loop
- Loading branch information
Showing
3 changed files
with
73 additions
and
17 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
core/runtime/src/main/java/io/quarkiverse/langchain4j/runtime/VertxUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkiverse.langchain4j.runtime; | ||
|
||
import java.util.concurrent.Callable; | ||
|
||
import io.smallrye.common.vertx.VertxContext; | ||
import io.smallrye.mutiny.infrastructure.Infrastructure; | ||
import io.vertx.core.Context; | ||
|
||
public class VertxUtil { | ||
|
||
public static void runOutEventLoop(Runnable runnable) { | ||
if (Context.isOnEventLoopThread()) { | ||
Context executionContext = VertxContext.getOrCreateDuplicatedContext(); | ||
if (executionContext != null) { | ||
executionContext.executeBlocking(new Callable<Object>() { | ||
@Override | ||
public Object call() { | ||
runnable.run(); | ||
return null; | ||
} | ||
}); | ||
} else { | ||
Infrastructure.getDefaultWorkerPool().execute(runnable); | ||
} | ||
} else { | ||
runnable.run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters