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

org.oscim.utils.async.AsyncExecutor Maven / Gradle / Ivy

Go to download

OpenGL vector map library written in Java - running on Android, iOS, Desktop and within the browser.

There is a newer version: 0.20.0
Show newest version
package org.oscim.utils.async;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.utils.Disposable;

/**
 * GWT emulation of AsynchExecutor, will call tasks immediately :D
 *
 * @author badlogic
 */
public class AsyncExecutor implements Disposable {
    private final TaskQueue mainloop;

    /**
     * Creates a new AsynchExecutor that allows maxConcurrent {@link Runnable}
     * instances to run in parallel.
     *
     * @param maxConcurrent
     */
    public AsyncExecutor(int maxConcurrent, TaskQueue mainloop) {
        this.mainloop = mainloop;
    }

    /**
     * Submits a {@link Runnable} to be executed asynchronously. If
     * maxConcurrent runnables are already running, the runnable
     * will be queued.
     *
     * @param task the task to execute asynchronously
     */
    public boolean post(Runnable task) {
        if (task instanceof AsyncTask) {
            ((AsyncTask) task).setTaskQueue(mainloop);
        }

        Gdx.app.postRunnable(task);

        return true;
    }

    /**
     * Waits for running {@link AsyncTask} instances to finish,
     * then destroys any resources like threads. Can not be used
     * after this method is called.
     */
    @Override
    public void dispose() {
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy