io.github.vipcxj.jasync.ng.spec.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jasync-spec Show documentation
Show all versions of jasync-spec Show documentation
JAsync implements Async-Await fashion for Java just like es and c#.
This library provide the spec of all public api.
package io.github.vipcxj.jasync.ng.spec;
import io.github.vipcxj.jasync.ng.spec.spi.PrioritySupport;
import java.util.ServiceLoader;
public class Utils {
public static T getProvider(Class type) {
ServiceLoader loader = ServiceLoader.load(type);
int p = PrioritySupport.PRIORITY_MIN;
T result = null;
for (T next : loader) {
if (next.priority() > p) {
result = next;
p = next.priority();
}
}
if (result == null) {
throw new IllegalStateException("Unable to find a provider of type " + type.getCanonicalName() + ".");
}
return result;
}
}