
package com.base.core.model;

import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class AccessRequestResult {

    private int taskNum;

    private final CountDownLatch  latch = new CountDownLatch(taskNum);

    private volatile Boolean isFinish;

    private Date resDate;

    public AccessRequestResult(int taskNum){
        this.taskNum = taskNum;
    }

    public void done(){
        if (this.isFinish == null){
            throw  new IllegalStateException("The method `set` must be invoked before this method.");
        }else {
            this.latch.countDown();
        }
    }

    public void await() throws InterruptedException{}

    public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
        return this.latch.await(timeout, unit);
    }
}