<commit_before>package com.admicro.vertx.utils;

import com.admicro.vertx.core.RunnableFuture;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public class TaskRunner {

    public static <T> void loopParallelTasks(RunnableFuture<T> rf, int count,
                                             Handler<AsyncResult<Void>> handler) {
        if (count <= 0) {
            handler.handle(Future.failedFuture("No tasks to run"));
            return;
        }

        AtomicInteger remainTasks = new AtomicInteger(count);
        AtomicBoolean finish = new AtomicBoolean(false);

        for (int i = 0; i < remainTasks.get(); i++) {
            Future<T> fut = Future.future();
            fut.setHandler(ar -> {
                if (!finish.get()) {
                    if (ar.failed()) {
                        finish.set(true);
                        handler.handle(Future.failedFuture(ar.cause()));
                    } else {
                        if (remainTasks.decrementAndGet() == 0) {
                            finish.set(true);
                            handler.handle(Future.succeededFuture());<commit_msg>Fix bug TaskRunner do not loop enough tasks<commit_after>package com.admicro.vertx.utils;

import com.admicro.vertx.core.RunnableFuture;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

public class TaskRunner {

    public static <T> void loopParallelTasks(RunnableFuture<T> rf, int count,
                                             Handler<AsyncResult<Void>> handler) {
        if (count <= 0) {
            handler.handle(Future.failedFuture("No tasks to run"));
            return;
        }

        AtomicInteger remainTasks = new AtomicInteger(count);
        AtomicBoolean finish = new AtomicBoolean(false);

        for (int i = 0; i < count; i++) {
            Future<T> fut = Future.future();
            fut.setHandler(ar -> {
                if (!finish.get()) {
                    if (ar.failed()) {
                        finish.set(true);
                        handler.handle(Future.failedFuture(ar.cause()));
                    } else {
                        if (remainTasks.decrementAndGet() == 0) {
                            finish.set(true);
                            handler.handle(Future.succeededFuture());
{'fraction_non_alphanumeric': 0.11141516810007819, 'fraction_numerical': 0.0023455824863174357, 'mean_word_length': 1.8151815181518152, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6032688', 'n_tokens_mistral': 702, 'n_tokens_neox': 663, 'n_words': 138}