All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.vipcxj.jasync.ng.spec.Utils Maven / Gradle / Ivy

Go to download

JAsync implements Async-Await fashion for Java just like es and c#. This library provide the spec of all public api.

There is a newer version: 1.0.17
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy