/*
* Copyright 2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ratpack.exec;
import ratpack.func.Action;
import ratpack.func.Factory;
import ratpack.func.Function;
import ratpack.func.Pair;
import ratpack.func.Predicate;
/**
* A promise for a single value.
*
* A promise is a representation of a value which will become available later.
* Methods such as {@link #map(Function)}, {@link #flatMap(Function)}, {@link #cache()} etc.) allow a pipeline of "operations" to be specified,
* that the value will travel through as it becomes available.
* Such operations are implemented via the {@link #transform(Function)} method.
* Each operation returns a new promise object, not the original promise object.
*
* To create a promise, use the {@link Promise#async(Upstream)} method (or one of the variants such as {@link Promise#sync(Factory)}.
* To test code that uses promises, use the {@link ratpack.test.exec.ExecHarness}.
*
* The promise is not "activated" until the {@link #then(Action)} method is called.
* This method terminates the pipeline, and receives the final value.
*
* Promise objects are multi use.
* Every promise pipeline has a value producing function at its start.
* Activating a promise (i.e. calling {@link #then(Action)}) invokes the function.
* The {@link #cache()} operation can be used to change this behaviour.
*
* @param the type of promised value
*/
@SuppressWarnings("JavadocReference")
public interface Promise {
static Promise sync(Factory factory) {
return null;
}
static Promise flatten(Factory extends Promise> factory) {
return null;
}
static Promise value(T t) {
return null;
}
Promise map(Function super T, ? extends O> transformer);
Promise flatMap(Function super T, ? extends Promise> transformer);
void then(Action super T> then);
Promise next(Action super T> action);
default Promise nextOp(Function super T, ? extends Operation> function) {
return null;
}
default Promise nextOpIf(Predicate super T> predicate, Function super T, ? extends Operation> function) {
return null;
}
default Promise onError(Class errorType, Action super E> errorHandler) {
return null;
}
default Promise onError(Action super Throwable> errorHandler) {
return null;
}
default Promise mapIf(Predicate super T> predicate, Function super T, ? extends T> transformer) {
return null;
}
default Promise mapIf(Predicate super T> predicate, Function super T, ? extends O> onTrue, Function super T, ? extends O> onFalse) {
return null;
}
default Promise blockingMap(Function super T, ? extends O> transformer) {
return null;
}
default Promise blockingOp(Action super T> action) {
return null;
}
default Promise replace(Promise next) {
return null;
}
default Promise> left(Promise left) {
return null;
}
default Promise> left(Function super T, ? extends O> leftFunction) {
return null;
}
default Promise> flatLeft(Function super T, ? extends Promise> leftFunction) {
return null;
}
default Promise> right(Promise right) {
return null;
}
default Promise> right(Function super T, ? extends O> rightFunction) {
return null;
}
default Promise> flatRight(Function super T, ? extends Promise> rightFunction) {
return null;
}
default Operation flatOp(Function super T, ? extends Operation> function) {
return null;
}
default Promise mapError(Function super Throwable, ? extends T> transformer) {
return null;
}
default Promise mapError(Class type, Function super E, ? extends T> function) {
return null;
}
default Promise mapError(Predicate super Throwable> predicate, Function super Throwable, ? extends T> function) {
return null;
}
default Promise flatMapError(Function super Throwable, ? extends Promise> function) {
return null;
}
default Promise flatMapError(Class type, Function super E, ? extends Promise> function) {
return null;
}
default Promise flatMapError(Predicate super Throwable> predicate, Function super Throwable, ? extends Promise> function) {
return null;
}
default Promise route(Predicate super T> predicate, Action super T> action) {
return null;
}
default Promise cache() {
return null;
}
default Promise cacheIf(Predicate super T> shouldCache) {
return null;
}
default Promise wiretap(Action super Result> listener) {
return null;
}
default Promise fork() {
return null;
}
default Promise apply(Function super Promise, ? extends Promise> function) {
return null;
}
}