Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.

Commit bf1434c

Browse files
committed
run on separate thread
1 parent 0e32a33 commit bf1434c

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

flo-workflow/src/main/java/com/spotify/flo/context/OverridingContext.java

+19-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.spotify.flo.Task;
2727
import com.spotify.flo.TaskContextStrict;
2828
import java.util.Optional;
29-
import java.util.function.Function;
3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
3231

@@ -46,21 +45,30 @@ public static EvalContext composeWith(EvalContext baseContext) {
4645

4746
@Override
4847
public <T> Value<T> evaluateInternal(Task<T> task, EvalContext context) {
49-
final Optional<T> lookup =
48+
final Optional<? extends TaskContextStrict<?, T>> taskContextStrict =
5049
task.contexts().stream()
5150
.filter(c -> c instanceof TaskContextStrict)
5251
.map(c -> (TaskContextStrict<?, T>) c)
53-
.map(l -> l.lookup(task))
54-
.findFirst()
55-
.flatMap(Function.identity());
52+
.findFirst();
5653

57-
if (lookup.isPresent()) {
58-
final T t = lookup.get();
59-
LOG.debug("Not expanding {}, lookup = {}", colored(task.id()), t);
60-
return context.immediateValue(t);
54+
if (taskContextStrict.isPresent()) {
55+
return context.value(() -> taskContextStrict.get().lookup(task))
56+
.flatMap(v -> {
57+
if (v.isPresent()) {
58+
final T t = v.get();
59+
LOG.debug("Not expanding {}, lookup = {}", colored(task.id()), t);
60+
return context.immediateValue(t);
61+
} else {
62+
return delegateEvaluation(task, context);
63+
}
64+
});
6165
} else {
62-
LOG.debug("Expanding {}", colored(task.id()));
63-
return delegate.evaluateInternal(task, context);
66+
return delegateEvaluation(task, context);
6467
}
6568
}
69+
70+
private <T> Value<T> delegateEvaluation(Task<T> task, EvalContext context) {
71+
LOG.debug("Expanding {}", colored(task.id()));
72+
return delegate.evaluateInternal(task, context);
73+
}
6674
}

0 commit comments

Comments
 (0)