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

io.machinecode.then.core.OnceDeferred Maven / Gradle / Ivy

package io.machinecode.then.core;

import io.machinecode.then.api.CancelledException;
import io.machinecode.then.api.RejectedException;
import io.machinecode.then.api.ResolvedException;

/**
 * 

A {@link io.machinecode.then.api.Deferred} implementation that will throw a {@link io.machinecode.then.api.CompletionException} * if completion is attempted multiple times.

* *

{@link #cancel(boolean)} will never throw a completion exception in order to maintain compatibility * with {@link java.util.concurrent.Future#cancel(boolean)}

* * @author Brent Douglas * @since 1.0 */ public class OnceDeferred extends DeferredImpl { @Override protected boolean setValue(final T value) { switch (this.state) { case REJECTED: throw new RejectedException(Messages.get("THEN-000103.promise.already.rejected")); case RESOLVED: throw new ResolvedException(Messages.get("THEN-000102.promise.already.resolved")); case CANCELLED: throw new CancelledException(Messages.get("THEN-000104.promise.already.cancelled")); default: this.value = value; this.state = RESOLVED; } return false; } @Override protected boolean setFailure(final F failure) { switch (this.state) { case REJECTED: throw new RejectedException(Messages.get("THEN-000103.promise.already.rejected")); case RESOLVED: throw new ResolvedException(Messages.get("THEN-000102.promise.already.resolved")); case CANCELLED: throw new CancelledException(Messages.get("THEN-000104.promise.already.cancelled")); default: this.failure = failure; this.state = REJECTED; } return false; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy