package com.izouma.nineth.aspect.debounce;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;

import java.util.concurrent.Callable;
import java.util.function.Function;

@Slf4j
public class DebounceTask implements Callable<Void> {
    private final ProceedingJoinPoint  joinPoint;
    private final Function<Void, Void> callback;

    public DebounceTask(ProceedingJoinPoint joinPoint, Function<Void, Void> callback) {
        this.joinPoint = joinPoint;
        this.callback = callback;
    }

    @Override
    public Void call() throws Exception {
        try {
            this.joinPoint.proceed();
            if (this.callback != null) {
                this.callback.apply(null);
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }

        return null;

    }
}
