package io.domisum.lib.auxiliumlib.work;

import io.domisum.lib.auxiliumlib.annotations.API;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import javax.annotation.Nullable;
import java.util.function.Consumer;

@RequiredArgsConstructor
public final class ReservedWork<T>
	implements AutoCloseable
{
	
	@Getter
	private final T subject;
	
	// STATUS
	@Getter
	private boolean successful = false;
	@Nullable
	private final Consumer<T> onSuccessful;
	
	@Getter
	private boolean closed = false;
	@Nullable
	private final Consumer<T> onClose;
	
	
	// INIT
	@API
	public static <T> ReservedWork<T> of(T work)
	{
		return new ReservedWork<>(work, null, null);
	}
	
	@API
	public static <T> ReservedWork<T> ofOnSuccessfulOnClose(T work, Consumer<T> onSuccessful, Consumer<T> onClose)
	{
		return new ReservedWork<>(work, onSuccessful, onClose);
	}
	
	
	// STATUS
	public void successful()
	{
		successful = true;
		
		if(onSuccessful != null)
			onSuccessful.accept(subject);
	}
	
	@Override
	public void close()
	{
		closed = true;
		
		if(onClose != null)
			onClose.accept(subject);
	}
	
}

@@ -605,20 +605,23 @@
 T%3E of(T 
-work
+subject
 )%0A%09%7B%0A%09%09r
@@ -649,24 +649,171 @@
 k%3C%3E(
-work, null, null
+subject, null, null);%0A%09%7D%0A%09%0A%09@API%0A%09public static %3CT%3E ReservedWork%3CT%3E ofOnClose(T subject, Consumer%3CT%3E onClose)%0A%09%7B%0A%09%09return new ReservedWork%3C%3E(subject, null, onClose
 );%0A%09
@@ -881,20 +881,23 @@
 Close(T 
-work
+subject
 , Consum
@@ -968,20 +968,23 @@
 dWork%3C%3E(
-work
+subject
 , onSucc

Add ReservedWork#ofOnClose