All Downloads are FREE. Search and download functionalities are using the official Maven repository.

functionalj.promise.DeferAction Maven / Gradle / Ivy

There is a newer version: 1.0.17
Show newest version
// ============================================================================
// Copyright (c) 2017-2021 Nawapunth Manusitthipol (NawaMan - http://nawaman.net).
// ----------------------------------------------------------------------------
// MIT License
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ============================================================================
package functionalj.promise;

import static functionalj.function.Func.carelessly;
import static functionalj.function.Func.f;
import static functionalj.list.FuncList.listOf;
import static functionalj.promise.RaceResult.Race;

import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

import functionalj.environments.AsyncRunner;
import functionalj.function.Func0;
import functionalj.function.Func1;
import functionalj.function.Func2;
import functionalj.function.Func3;
import functionalj.function.Func4;
import functionalj.function.Func5;
import functionalj.function.Func6;
import functionalj.function.FuncUnit0;
import functionalj.function.FuncUnit1;
import functionalj.function.FuncUnit2;
import functionalj.function.NamedExpression;
import functionalj.list.FuncList;
import functionalj.pipeable.Pipeable;
import functionalj.result.Result;
import functionalj.result.ResultStatus;
import functionalj.result.ValidationException;
import functionalj.tuple.Tuple2;
import functionalj.validator.Validator;
import lombok.val;


@SuppressWarnings({ "unchecked", "rawtypes" })
public class DeferAction extends UncompletedAction implements Pipeable> {
    
    public static  DeferAction createNew() {
        return of((Class)null);
    }
    public static  DeferAction createNew(OnStart onStart) {
        return of((Class)null, onStart);
    }
    public static  DeferAction of(Class clzz) {
        return new DeferAction();
    }
    public static  DeferAction of(Class clzz, OnStart onStart) {
        return new DeferAction(null, onStart);
    }
    
    public static  DeferAction ofValue(D value) {
        val action = new DeferAction();
        action.getPromise().makeComplete(value);
        return action;
    }
    
    public static DeferAction defer(FuncUnit0 runnable) {
        return DeferAction.from(runnable);
    }
    public static  DeferAction defer(Func0 supplier) {
        return DeferAction.from(supplier);
    }
    public static  DeferAction defer(CompletableFuture completableFucture) {
        return DeferAction.from(completableFucture);
    }
    
    public static DeferAction from(FuncUnit0 runnable) {
        return DeferActionConfig.current.value().createBuilder(runnable).build();
    }
    public static  DeferAction from(Func0 supplier) {
        return DeferActionConfig.current.value().createBuilder(supplier).build();
    }
    public static  DeferAction from(CompletableFuture completableFucture) {
        val action = DeferAction.of((Class)null);
        val pending = action.start();
        
        completableFucture.handle((value, exception) -> {
            if (exception != null) {
                if (exception instanceof Exception)
                     pending.fail((Exception)exception);
                else pending.fail(new RuntimeException("CompletableFuture completed with failure: ", exception));
            } else {
                pending.complete(value);
            }
            
            return null;
        });
        return action;
    }
    
    public static PendingAction run(FuncUnit0 runnable) {
        return DeferAction.from(runnable)
                .start();
    }
    public static  PendingAction run(Func0 supplier) {
        return DeferAction.from(supplier)
                .start();
    }
    
    @SafeVarargs
    public static  RaceResult AnyOf(StartableAction ... actions) {
        return Race(FuncList.of(actions));
    }
    
    public static  RaceResult AnyOf(List> actions) {
        return Race(actions);
    }
    @SafeVarargs
    public static  RaceResult race(StartableAction ... actions) {
        return Race(FuncList.of(actions));
    }
    
    public static  RaceResult race(List> actions) {
        return Race(actions);
    }
    
    
    public static  DeferAction from(
            NamedExpression> promise1,
            NamedExpression> promise2,
            Func2                merger) {
        val merge = (Func1)f((FuncList results)-> {
            val result1 = (Result)results.get(0);
            val result2 = (Result)results.get(1);
            val mergedResult = Result.ofResults(result1, result2, merger);
            return (Result)mergedResult;
        });
        val promises = listOf(promise1, promise2);
        val combiner = new CombineResult(promises, merge);
        val action   = combiner.getDeferAction();
        return action;
    }
    
    public static  DeferAction from(
            NamedExpression> promise1,
            NamedExpression> promise2,
            NamedExpression> promise3,
            Func3            merger) {
        val merge = (Func1)f((FuncList results)-> {
            val result1 = (Result)results.get(0);
            val result2 = (Result)results.get(1);
            val result3 = (Result)results.get(2);
            val mergedResult = Result.ofResults(result1, result2, result3, merger);
            return (Result)mergedResult;
        });
        val promises = listOf(promise1, promise2, promise3);
        val combiner = new CombineResult(promises, merge);
        val action   = combiner.getDeferAction();
        return action;
    }
    
    public static  DeferAction from(
            NamedExpression> promise1,
            NamedExpression> promise2,
            NamedExpression> promise3,
            NamedExpression> promise4,
            Func4        merger) {
        val merge = (Func1)f((FuncList results)-> {
            val result1 = (Result)results.get(0);
            val result2 = (Result)results.get(1);
            val result3 = (Result)results.get(2);
            val result4 = (Result)results.get(3);
            val mergedResult = Result.ofResults(result1, result2, result3, result4, merger);
            return (Result)mergedResult;
        });
        val promises = listOf(promise1, promise2, promise3, promise4);
        val combiner = new CombineResult(promises, merge);
        val action   = combiner.getDeferAction();
        return action;
    }
    
    public static  DeferAction from(
            NamedExpression> promise1,
            NamedExpression> promise2,
            NamedExpression> promise3,
            NamedExpression> promise4,
            NamedExpression> promise5,
            Func5    merger) {
        val merge = (Func1)f((FuncList results)-> {
            val result1 = (Result)results.get(0);
            val result2 = (Result)results.get(1);
            val result3 = (Result)results.get(2);
            val result4 = (Result)results.get(3);
            val result5 = (Result)results.get(4);
            val mergedResult = Result.ofResults(result1, result2, result3, result4, result5, merger);
            return (Result)mergedResult;
        });
        val promises = listOf(promise1, promise2, promise3, promise4, promise5);
        val combiner = new CombineResult(promises, merge);
        val action   = combiner.getDeferAction();
        return action;
    }
    
    public static  DeferAction from(
            NamedExpression>  promise1,
            NamedExpression>  promise2,
            NamedExpression>  promise3,
            NamedExpression>  promise4,
            NamedExpression>  promise5,
            NamedExpression>  promise6,
            Func6 merger) {
        val merge = (Func1)f((FuncList results)-> {
            val result1 = (Result)results.get(0);
            val result2 = (Result)results.get(1);
            val result3 = (Result)results.get(2);
            val result4 = (Result)results.get(3);
            val result5 = (Result)results.get(4);
            val result6 = (Result)results.get(5);
            val mergedResult = Result.ofResults(result1, result2, result3, result4, result5, result6, merger);
            return (Result)mergedResult;
        });
        val promises = listOf(promise1, promise2, promise3, promise4, promise5, promise6);
        val combiner = new CombineResult(promises, merge);
        val action   = combiner.getDeferAction();
        return action;
    }
    
    public static  DeferAction from(
            Func1, D> merger,
            NamedExpression> ... promises) {
        val merge = f((Result[] results)-> {
            val resultList = listOf(results).map(Result::get);
            val mergedResult = merger.apply(resultList);
            return (Result)mergedResult;
        });
        val promiseList = listOf(promises);
        val combiner    = new CombineResult(promiseList, merge);
        val action      = combiner.getDeferAction();
        return action;
    }
    
    
    public static  DeferAction create(
            boolean     interruptOnCancel,
            Func0    supplier,
            Runnable    onStart,
            AsyncRunner runner) {
        return DeferActionCreator.current.value()
                .create(supplier, onStart, interruptOnCancel, runner);
    }
    
    private final Runnable task;
    
    private final DeferAction parent;
    
    DeferAction() {
        this(null, (OnStart)null);
    }
    DeferAction(DeferAction parent, Promise promise) {
        super(promise);
        this.parent = parent;
        this.task   = null;
    }
    DeferAction(Runnable task, OnStart onStart) {
        super(onStart);
        this.parent = null;
        this.task   = task;
    }
    
    public PendingAction start() {
        if (parent != null) {
            parent.start();
        } else {
            val isStarted = promise.start();
            
            if (!isStarted && (task != null))
                carelessly(task);
        }
        return new PendingAction<>(promise);
    }
    
    public HasPromise __data() throws Exception {
        return this;
    }
    
    //== Subscription ==
    
    public DeferAction use(Consumer> consumer) {
        carelessly(()->{
            consumer.accept(promise);
        });
        
        return this;
    }
    
    public DeferAction abortNoSubsriptionAfter(Wait wait) {
        promise.abortNoSubscriptionAfter(wait);
        return this;
    }
    
    public DeferAction subscribe(FuncUnit1 resultConsumer) {
        promise.subscribe(Wait.forever(), resultConsumer);
        return this;
    }
    
    public final DeferAction subscribe(Wait wait, FuncUnit1 resultConsumer) {
        promise.subscribe(wait, resultConsumer);
        return this;
    }
    
    public DeferAction onComplete(FuncUnit1> resultConsumer) {
        promise.onComplete(Wait.forever(), resultConsumer);
        return this;
    }
    
    public DeferAction onComplete(Wait wait, FuncUnit1> resultConsumer) {
        promise.onComplete(wait, resultConsumer);
        return this;
    }
    
    public DeferAction onComplete(
            FuncUnit1>       resultConsumer,
            FuncUnit1> subscriptionConsumer) {
        val subscription = promise.onComplete(Wait.forever(), resultConsumer);
        carelessly(() -> subscriptionConsumer.accept(subscription));
        return this;
    }
    
    public DeferAction onComplete(
            Wait                          wait,
            FuncUnit1>       resultConsumer,
            FuncUnit1> subscriptionConsumer) {
        val subscription = promise.onComplete(wait, resultConsumer);
        carelessly(() -> subscriptionConsumer.accept(subscription));
        return this;
    }
    
    public DeferAction eavesdrop(FuncUnit1> resultConsumer) {
        promise.eavesdrop(resultConsumer);
        return this;
    }
    
    public DeferAction eavesdrop(Wait wait, FuncUnit1> resultConsumer) {
        promise.eavesdrop(wait, resultConsumer);
        return this;
    }
    
    //== Functional ==
    
    public final DeferAction filter(Predicate predicate) {
        val newPromise = promise.filter(predicate);
        return new DeferAction(this, newPromise);
    }
    
    public final DeferAction peek(FuncUnit1 peeker) {
        val newPromise = promise.peek(peeker);
        return new DeferAction(this, (Promise)newPromise);
    }
    
    public final  DeferAction map(Func1 mapper) {
        val newPromise = promise.map(mapper);
        val newAction  = new DeferAction(this, (Promise)newPromise);
        return newAction;
    }
    
    public final  DeferAction flatMap(Func1> mapper) {
        return chain((Func1)mapper);
    }
    
    public final  DeferAction chain(Func1> mapper) {
        val newPromise = promise.chain(mapper);
        return new DeferAction(this, (Promise)newPromise);
    }
    
    //== Status ==
    
    public DeferAction ifStatusRun(ResultStatus status, Runnable runnable) {
        return new DeferAction(this, promise.ifStatusRun(status, runnable));
    }
    
    public DeferAction ifStatusAccept(ResultStatus status, Consumer consumer) {
        return new DeferAction(this, promise.ifStatusAccept(status, consumer));
    }
    
    public DeferAction whenStatusUse(ResultStatus status, DATA fallbackValue) {
        return new DeferAction(this, promise.whenStatusUse(status, fallbackValue));
    }
    public DeferAction whenStatusGet(ResultStatus status, Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenStatusGet(status, fallbackSupplier));
    }
    public DeferAction whenStatusApply(ResultStatus status, BiFunction recoverFunction) {
        return new DeferAction(this, promise.whenStatusApply(status, recoverFunction));
    }
    
    //== Validation ==
    
    public DeferAction validateNotNull() {
        return new DeferAction(this, promise.validateNotNull());
    }
    public DeferAction validateNotNull(String message) {
        return new DeferAction(this, promise.validateNotNull(message));
    }
    public DeferAction validateUnavailable() {
        return new DeferAction(this, promise.validateUnavailable());
    }
    public DeferAction validateNotReady() {
        return new DeferAction(this, promise.validateNotReady());
    }
    public DeferAction validateResultCancelled() {
        return new DeferAction(this, promise.validateResultCancelled());
    }
    public DeferAction validateResultNotExist() {
        return new DeferAction(this, promise.validateResultNotExist());
    }
    public DeferAction validateNoMoreResult() {
        return new DeferAction(this, promise.validateNoMoreResult());
    }
    
    public DeferAction validate(String stringFormat, Predicate validChecker) {
        return new DeferAction(this, promise.validate(stringFormat, validChecker));
    }
    
    public  DeferAction validate(String stringFormat, Func1 mapper, Predicate validChecker) {
        return new DeferAction(this, promise.validate(stringFormat, mapper, validChecker));
    }
    public DeferAction validate(Validator validator) {
        return new DeferAction(this, promise.validate(validator));
    }
    
    public DeferAction>> validate(Validator ... validators) {
        return new DeferAction>>(this, promise.validate(validators));
    }
    
    public DeferAction>> validate(List> validators) {
        return new DeferAction>>(this, promise.validate(validators));
    }
    
    public DeferAction ensureNotNull() {
        return new DeferAction(this, promise.ensureNotNull());
    }
    
    // Alias of whenNotPresentUse
    public DeferAction otherwise(DATA elseValue) {
        return new DeferAction(this, promise.otherwise(elseValue));
    }
    
    // Alias of whenNotPresentGet
    public DeferAction otherwiseGet(Supplier elseSupplier) {
        return new DeferAction(this, promise.otherwiseGet(elseSupplier));
    }
    
    public DeferAction printException() {
        return new DeferAction(this, promise.printException());
    }
    
    public DeferAction printException(PrintStream printStream) {
        return new DeferAction(this, promise.printException(printStream));
    }
    
    public DeferAction printException(PrintWriter printWriter) {
        return new DeferAction(this, promise.printException(printWriter));
    }
    
    //== Peek ==
    
    public  DeferAction peek(Class clzz, Consumer theConsumer) {
        return new DeferAction(this, promise.peek(clzz, theConsumer));
    }
    public DeferAction peek(Predicate selector, Consumer theConsumer) {
        return new DeferAction(this, promise.peek(selector, theConsumer));
    }
    public  DeferAction peek(Function mapper, Consumer theConsumer) {
        return new DeferAction(this, promise.peek(mapper, theConsumer));
    }
    
    public  DeferAction peek(Function mapper, Predicate selector, Consumer theConsumer) {
        return new DeferAction(this, promise.peek(mapper, selector, theConsumer));
    }
    
    //== If+When ==
    
    public DeferAction useData(FuncUnit2 processor) {
        return new DeferAction(this, promise.useData(processor));
    }
    
    public DeferAction whenComplete(FuncUnit2 processor) {
        return new DeferAction(this, promise.whenComplete(processor));
    }
    
    public DeferAction whenComplete(FuncUnit1> processor) {
        return new DeferAction(this, promise.whenComplete(processor));
    }
    
    //== Present ==
    
    public DeferAction ifPresent(Runnable runnable) {
        return new DeferAction(this, promise.ifPresent(runnable));
    }
    
    public DeferAction ifPresent(Consumer consumer) {
        return new DeferAction(this, promise.ifPresent(consumer));
    }
    
    //== Absent ==
    
    public DeferAction ifAbsent(Runnable runnable) {
        return new DeferAction(this, promise.ifAbsent(runnable));
    }
    
    public DeferAction ifAbsent(Consumer consumer) {
        return new DeferAction(this, promise.ifAbsent(consumer));
    }
    
    public DeferAction ifAbsent(BiConsumer consumer) {
        return new DeferAction(this, promise.ifAbsent(consumer));
    }
    
    public DeferAction whenAbsentUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenAbsentUse(fallbackValue));
    }
    
    public DeferAction whenAbsentGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenAbsentGet(fallbackSupplier));
    }
    
    public DeferAction whenAbsentApply(BiFunction recoverFunction) {
        return new DeferAction(this, promise.whenAbsentApply(recoverFunction));
    }
    
    //== Null ==
    
    public DeferAction ifNull(Runnable runnable) {
        return new DeferAction(this, promise.ifNull(runnable));
    }
    
    public DeferAction whenNullUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenNullUse(fallbackValue));
    }
    public DeferAction whenNullGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenNullGet(fallbackSupplier));
    }
    
    //== Value ==
    
    public DeferAction ifValue(Runnable runnable) {
        return new DeferAction(this, promise.ifValue(runnable));
    }
    
    public DeferAction ifValue(Consumer consumer) {
        return new DeferAction(this, promise.ifValue(consumer));
    }
    
    //== NotValue ==
    
    public DeferAction ifNotValue(Runnable runnable) {
        return new DeferAction(this, promise.ifNotValue(runnable));
    }
    
    public DeferAction ifNotValue(Consumer consumer) {
        return new DeferAction(this, promise.ifNotValue(consumer));
    }
    
    public DeferAction ifNotValue(BiConsumer consumer) {
        return new DeferAction(this, promise.ifNotValue(consumer));
    }
    
    public DeferAction whenNotValueUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenNotValueUse(fallbackValue));
    }
    public DeferAction whenNotValueGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenNotValueGet(fallbackSupplier));
    }
    public DeferAction whenNotValueApply(BiFunction recoverFunction) {
        return new DeferAction(this, promise.whenNotValueApply(recoverFunction));
    }
    
    //== Valid ==
    
    public DeferAction ifValid(Consumer consumer) {
        return new DeferAction(this, promise.ifValid(consumer));
    }
    
    //== Invalid ==
    
    public DeferAction ifInvalid(Runnable runnable) {
        return new DeferAction(this, promise.ifInvalid(runnable));
    }
    
    public DeferAction ifInvalid(Consumer consumer) {
        return new DeferAction(this, promise.ifInvalid(consumer));
    }
    
    public DeferAction whenInvalidUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenInvalidUse(fallbackValue));
    }
    public DeferAction whenInvalidGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenInvalidGet(fallbackSupplier));
    }
    public DeferAction whenInvalidApply(Function recoverFunction) {
        return new DeferAction(this, promise.whenInvalidApply(recoverFunction));
    }
    
    //== NotExist ==
    
    public DeferAction ifNotExist(Runnable runnable) {
        return new DeferAction(this, promise.ifNotExist(runnable));
    }
    
    public DeferAction ifNotExist(Consumer consumer) {
        return new DeferAction(this, promise.ifNotExist(consumer));
    }
    
    public DeferAction whenNotExistUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenNotExistUse(fallbackValue));
    }
    public DeferAction whenNotExistGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenNotExistGet(fallbackSupplier));
    }
    public DeferAction whenNotExistApply(Function recoverFunction) {
        return new DeferAction(this, promise.whenNotExistApply(recoverFunction));
    }
    
    //== Exception ==
    
    public DeferAction ifException(Runnable runnable) {
        return new DeferAction(this, promise.ifException(runnable));
    }
    
    public DeferAction ifException(Consumer consumer) {
        return new DeferAction(this, promise.ifException(consumer));
    }
    
    public DeferAction ifExceptionThenPrint() {
        return new DeferAction(this, promise.ifExceptionThenPrint());
    }
    public DeferAction ifExceptionThenPrint(PrintStream printStream) {
        return new DeferAction(this, promise.ifExceptionThenPrint(printStream));
    }
    public DeferAction ifExceptionThenPrint(PrintWriter printWriter) {
        return new DeferAction(this, promise.ifExceptionThenPrint(printWriter));
    }
    
    public DeferAction whenExceptionUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenExceptionUse(fallbackValue));
    }
    public DeferAction whenExceptionGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenExceptionGet(fallbackSupplier));
    }
    public DeferAction whenExceptionApply(Function recoverFunction) {
        return new DeferAction(this, promise.whenExceptionApply(recoverFunction));
    }
    
    public DeferAction recover(DATA fallbackValue) {
        return recover(Exception.class, fallbackValue);
    }
    public DeferAction recover(Supplier fallbackSupplier) {
        return recover(Exception.class, fallbackSupplier);
    }
    public DeferAction recover(Func1 recoverFunction) {
        return recover(Exception.class, recoverFunction);
    }
    public DeferAction recover(Class problemClass, DATA fallbackValue) {
        return new DeferAction(this, promise.recover(problemClass, fallbackValue));
    }
    public DeferAction recover(Class problemClass, Supplier fallbackSupplier) {
        return new DeferAction(this, promise.recover(problemClass, fallbackSupplier));
    }
    public DeferAction recover(Class problemClass, Func1 recoverFunction) {
        return new DeferAction(this, promise.recover(problemClass, recoverFunction));
    }
    
    //== Cancelled ==
    
    public DeferAction ifCancelled(Runnable runnable) {
        return new DeferAction(this, promise.ifCancelled(runnable));
    }
    
    public DeferAction whenCancelledUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenCancelledUse(fallbackValue));
    }
    public DeferAction whenCancelledGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenCancelledGet(fallbackSupplier));
    }
    public DeferAction whenCancelledApply(Function recoverFunction) {
        return new DeferAction(this, promise.whenCancelledApply(recoverFunction));
    }
    
    //== Ready ==
    
    public DeferAction ifReady(Runnable runnable) {
        return new DeferAction(this, promise.ifReady(runnable));
    }
    
    public DeferAction ifReady(Consumer consumer) {
        return new DeferAction(this, promise.ifReady(consumer));
    }
    
    public DeferAction ifReady(BiConsumer consumer) {
        return new DeferAction(this, promise.ifReady(consumer));
    }
    
    public DeferAction whenReadyUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenReadyUse(fallbackValue));
    }
    public DeferAction whenReadyGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenReadyGet(fallbackSupplier));
    }
    public DeferAction whenNotReadyApply(BiFunction recoverFunction) {
        return new DeferAction(this, promise.whenNotReadyApply(recoverFunction));
    }
    
    //== Not Ready ==
    
    public DeferAction ifNotReady(Runnable runnable) {
        return new DeferAction(this, promise.ifNotReady(runnable));
    }
    public DeferAction ifNotReady(Consumer consumer) {
        return new DeferAction(this, promise.ifNotReady(consumer));
    }
    
    public DeferAction whenNotReadyUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenNotReadyUse(fallbackValue));
    }
    public DeferAction whenNotReadyGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenNotReadyGet(fallbackSupplier));
    }
    public DeferAction whenNotReadyApply(Function recoverFunction) {
        return new DeferAction(this, promise.whenNotReadyApply(recoverFunction));
    }
    
    //== No More Result ==
    
    public DeferAction ifNoMore(Runnable runnable) {
        return new DeferAction(this, promise.ifNoMore(runnable));
    }
    public DeferAction ifNoMore(Consumer consumer) {
        return new DeferAction(this, promise.ifNoMore(consumer));
    }
    
    public DeferAction whenNoMoreUse(DATA fallbackValue) {
        return new DeferAction(this, promise.whenNoMoreUse(fallbackValue));
    }
    public DeferAction whenNoMoreGet(Supplier fallbackSupplier) {
        return new DeferAction(this, promise.whenNoMoreGet(fallbackSupplier));
    }
    public DeferAction whenNoMoreApply(Function recoverFunction) {
        return new DeferAction(this, promise.whenNoMoreApply(recoverFunction));
    }
    
}