package com.foxx.androidcast.util;

/*********************************************************************
 * CastBackgroundExecutor.java
 * Created at: Sun 17 May 2026 15:45:19 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class CastBackgroundExecutor
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 34 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	caa7524841be0925f61bfb5624995b82946819e74e66a4930ef8d529ac16f28c
**********************************************************************/
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/** Shared daemon executor for short background tasks (consent, session stats I/O). */
public final class CastBackgroundExecutor {
    private static final AtomicInteger SEQ = new AtomicInteger();
    private static final ExecutorService EXEC = Executors.newSingleThreadExecutor(new ThreadFactory() {
        @Override
        public Thread newThread(Runnable r) {
            Thread t = new Thread(r, "CastBackground-" + SEQ.incrementAndGet());
            t.setDaemon(true);
            return t;
        }
    });

    private CastBackgroundExecutor() {}

    public static void execute(Runnable task) {
        if (task != null) {
            EXEC.execute(task);
        }
    }
}
