package be.iminds.ilabt.jfed.experimenter_gui.util;

import be.iminds.ilabt.jfed.highlevel.controller.TaskExecution;
import javafx.concurrent.Task;

import java.util.LinkedList;
import java.util.Queue;

/**
 * User: twalcari
 * Date: 8/3/2015
 * Time: 10:42
 */
public abstract class WaitForTaskExecutionsTask extends Task<Void> {

    private final Queue<TaskExecution> taskExecutions = new LinkedList<>();

    public void addTaskExecution(TaskExecution taskExecution){
        taskExecutions.add(taskExecution);
    }


    @Override
    protected final Void call() throws Exception {
        while(!taskExecutions.isEmpty()){

            TaskExecution taskExecution = taskExecutions.poll();

            while(!taskExecution.isCompleted())
                Thread.sleep(250);
        }

        onTaskExecutionsFinished();

        return null;
    }

    public abstract void onTaskExecutionsFinished();


}
