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

Inline loom-compatibility #166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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