package com.example.PhotoGallery.Components;

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

import org.springframework.stereotype.Component;

@Component
public class ImageIngestionCoordinator {

    private final AtomicBoolean running = new AtomicBoolean(false);

    public boolean startIfNotRunning(Runnable task) {
        if (running.compareAndSet(false, true)) {
            CompletableFuture.runAsync(() -> {
                try {
                    task.run();
                } finally {
                    running.set(false);
                }
            });
            return true;
        }
        return false;
    }
}

