Skip to content

Commit

Permalink
Inline loom-compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
sideeffffect committed Feb 4, 2025
1 parent 0fc00e2 commit 776e648
Show file tree
Hide file tree
Showing 6 changed files with 558 additions and 0 deletions.
16 changes: 16 additions & 0 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,23 @@ trait LocalModule extends CrossScalaModule{
def moduleDeps = Seq(cask(crossScalaVersion))
}

object `loom-compatibility` extends JavaModule with PublishModule {

override def javacOptions: T[Seq[String]] = super.javacOptions() ++ List("-source", "8", "-target", "8")

def publishVersion = VcsVersion.vcsState().format()

def pomSettings = PomSettings(
description = artifactName(),
organization = "com.lihaoyi",
url = "https://github.com/com-lihaoyi/cask",
licenses = Seq(License.MIT),
versionControl = VersionControl.github("com-lihaoyi", "cask"),
developers = Seq(
Developer("lihaoyi", "Li Haoyi","https://github.com/lihaoyi")
)
)
}

def zippedExamples = T {
val vcsState = VcsVersion.vcsState()
Expand Down
45 changes: 45 additions & 0 deletions loom-compatibility/src/loom_compatibility/LoomExecutors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package loom_compatibility;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadFactory;

public interface LoomExecutors {

static LoomExecutors load() throws LoomUnavailable {
try {
return new LoomExecutorsImplementation();
} catch (LinkageError e) {
throw new LoomUnavailable(e);
}
}

/**
* Creates an Executor that starts a new Thread for each task.
* The number of threads created by the Executor is unbounded.
*
* <p> Invoking {@link Future#cancel(boolean) cancel(true)} on a {@link
* Future Future} representing the pending result of a task submitted to
* the Executor will {@link Thread#interrupt() interrupt} the thread
* executing the task.
*
* @param threadFactory the factory to use when creating new threads
* @return a new executor that creates a new Thread for each task
* @throws NullPointerException if threadFactory is null
* @since 21
*/
public ExecutorService newThreadPerTaskExecutor(ThreadFactory threadFactory);

/**
* Creates an Executor that starts a new virtual Thread for each task.
* The number of threads created by the Executor is unbounded.
*
* <p> This method is equivalent to invoking
* {@link #newThreadPerTaskExecutor(ThreadFactory)} with a thread factory
* that creates virtual threads.
*
* @return a new executor that creates a new virtual Thread for each task
* @since 21
*/
public ExecutorService newVirtualThreadPerTaskExecutor();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package loom_compatibility;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadFactory;

class LoomExecutorsImplementation implements LoomExecutors {
static {
Thread.ofVirtual();
}

@Override
public ExecutorService newThreadPerTaskExecutor(ThreadFactory threadFactory) {
return java.util.concurrent.Executors.newThreadPerTaskExecutor(threadFactory);
}

@Override
public ExecutorService newVirtualThreadPerTaskExecutor() {
return java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor();
}
}
Loading

0 comments on commit 776e648

Please sign in to comment.