org.jboss.hal.flow.FlowContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hal-flow Show documentation
Show all versions of hal-flow Show documentation
Async Flow based on Promise API
The newest version!
/*
* Copyright 2022 Red Hat
*
* 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
*
* https://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 org.jboss.hal.flow;
import java.util.EmptyStackException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.function.Predicate;
import elemental2.promise.Promise;
/**
* General purpose context to be used as a common data structure when executing a list of {@linkplain Task asynchronous tasks}
* in {@linkplain Flow#parallel(FlowContext, List) parallel}, in {@linkplain Flow#sequential(FlowContext, List) sequence} or
* when executing a task {@linkplain Flow#repeat(FlowContext, Task) repeatedly} while a {@linkplain Predicate condition}
* evaluates to {@code true}.
*
* The context provides a {@linkplain Progress progress indicator} to signal the progress of the task execution and a stack and
* a map for sharing data between {@linkplain Task asynchronous tasks}.
*
* Finally, the context provides methods to resolve the context as promise.
*/
public class FlowContext {
/**
* Method to check if the error in a {@linkplain Promise.CatchOnRejectedCallbackFn catch} callback is due to a timeout.
*/
public static boolean timeout(Object error) {
return error.equals(FlowRunner.TIMEOUT_ERROR);
}
private final Stack