Skip to content

[scheduler] add example of using Scheduler from Java#1121

Merged
hearnadam merged 1 commit into
getkyo:mainfrom
hearnadam:java-fascade
Mar 30, 2025
Merged

[scheduler] add example of using Scheduler from Java#1121
hearnadam merged 1 commit into
getkyo:mainfrom
hearnadam:java-fascade

Conversation

@hearnadam
Copy link
Copy Markdown
Collaborator

@hearnadam hearnadam commented Mar 30, 2025

Problem

The Scheduler is currently published as a Scala module, so I suspect users may not realize that it's available for other JVM applications.

#1111

Solution

Add an example test in Java to make sure our APIs are always accessible from Java - not depending on Scala specific features.

@hearnadam hearnadam changed the title [scheduler] add example of use Scheduler from Java [scheduler] add example of using Scheduler from Java Mar 30, 2025
Comment on lines +23 to +26
scheduler.schedule(Task.apply(() -> {
threadName.set(Thread.currentThread().getName());
latch.countDown();
}));
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should add a Function1 overload to Task.apply. Currently this is lifting to Runnable.
We could also add some overloads for task scheduling to the Scheduler itself.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Runnable is important to support because it's typically what people already have when invoking the scheduler. If we go with Scala's Function1 instead, it could require an extra wrapper allocation to adapt

AtomicReference<String> threadName = new AtomicReference<>("");
CountDownLatch latch = new CountDownLatch(1);

scheduler.schedule(Task.apply(() -> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! I wasn't expecting the Scala API to work this well from Java

@hearnadam hearnadam merged commit 0d19ff9 into getkyo:main Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants