/* * 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> factory) { return null; } static Promise value(T t) { return null; } Promise map(Function transformer); Promise flatMap(Function> transformer); void then(Action then); Promise next(Action action); default Promise nextOp(Function function) { return null; } default Promise nextOpIf(Predicate predicate, Function function) { return null; } default Promise onError(Class errorType, Action errorHandler) { return null; } default Promise onError(Action errorHandler) { return null; } default Promise mapIf(Predicate predicate, Function transformer) { return null; } default Promise mapIf(Predicate predicate, Function onTrue, Function onFalse) { return null; } default Promise blockingMap(Function transformer) { return null; } default Promise blockingOp(Action action) { return null; } default Promise replace(Promise next) { return null; } default Promise> left(Promise left) { return null; } default Promise> left(Function leftFunction) { return null; } default Promise> flatLeft(Function> leftFunction) { return null; } default Promise> right(Promise right) { return null; } default Promise> right(Function rightFunction) { return null; } default Promise> flatRight(Function> rightFunction) { return null; } default Operation flatOp(Function function) { return null; } default Promise mapError(Function transformer) { return null; } default Promise mapError(Class type, Function function) { return null; } default Promise mapError(Predicate predicate, Function function) { return null; } default Promise flatMapError(Function> function) { return null; } default Promise flatMapError(Class type, Function> function) { return null; } default Promise flatMapError(Predicate predicate, Function> function) { return null; } default Promise route(Predicate predicate, Action action) { return null; } default Promise cache() { return null; } default Promise cacheIf(Predicate shouldCache) { return null; } default Promise wiretap(Action> listener) { return null; } default Promise fork() { return null; } default Promise apply(Function, ? extends Promise> function) { return null; } }