4747
4848
4949/**
50- * TODO add extensive documentations
51- *
5250 * A task represents a deferred execution that also contains its resulting
5351 * value. In addition, tasks include tracing information that can be
5452 * used with various trace printers.
@@ -218,7 +216,9 @@ default <R> Task<R> map(final Function1<? super T, ? extends R> func) {
218216 */
219217 default <R > Task <R > flatMap (final String desc , final Function1 <? super T , Task <R >> func ) {
220218 ArgumentUtil .requireNotNull (func , "function" );
221- return flatten (desc , map ("flatMap" , func ));
219+ final Task <Task <R >> nested = map (func );
220+ nested .getShallowTraceBuilder ().setSystemHidden (true );
221+ return flatten (desc , nested );
222222 }
223223
224224 /**
@@ -266,11 +266,11 @@ default Task<T> withSideEffect(final String desc, final Function1<? super T, Tas
266266 Task <?> sideEffect = func .apply (that .get ());
267267 ctx .run (sideEffect );
268268 return sideEffect ;
269- } , true );
269+ });
270270 context .after (that ).runSideEffect (sideEffectWrapper );
271271 context .run (that );
272272 return that ;
273- } , true );
273+ });
274274 }
275275
276276 /**
@@ -288,7 +288,7 @@ default Task<T> shareable() {
288288 context .runSideEffect (that );
289289 Promises .propagateResult (that , result );
290290 return result ;
291- } , true );
291+ });
292292 }
293293
294294 /**
@@ -369,7 +369,7 @@ default <R> Task<R> andThen(final String desc, final Task<R> task) {
369369 Promises .propagateResult (task , result );
370370 context .run (that );
371371 return result ;
372- } , true );
372+ });
373373 }
374374
375375 /**
@@ -632,7 +632,7 @@ default Task<T> recoverWith(final String desc, final Function1<Throwable, Task<T
632632 final Task <T > that = this ;
633633 return async (desc , context -> {
634634 final SettablePromise <T > result = Promises .settable ();
635- final Task <T > recovery = async (desc , ctx -> {
635+ final Task <T > recovery = async ("revovery" , ctx -> {
636636 if (that .isFailed () && !(Exceptions .isCancellation (that .getError ()))) {
637637 try {
638638 Task <T > r = func .apply (that .getError ());
@@ -645,11 +645,12 @@ default Task<T> recoverWith(final String desc, final Function1<Throwable, Task<T
645645 result .done (that .get ());
646646 }
647647 return result ;
648- } , true );
648+ });
649+ recovery .getShallowTraceBuilder ().setSystemHidden (true );
649650 context .after (that ).run (recovery );
650651 context .run (that );
651652 return result ;
652- } , true );
653+ });
653654 }
654655
655656 /**
@@ -694,7 +695,7 @@ default Task<T> withTimeout(final long time, final TimeUnit unit) {
694695 that .setPriority (Priority .MAX_PRIORITY );
695696 ctx .run (that );
696697 return result ;
697- } , false );
698+ });
698699 withTimeout .setPriority (getPriority ());
699700 return withTimeout ;
700701 }
@@ -721,7 +722,7 @@ public static <R> Task<R> flatten(final String desc, final Task<Task<R>> task) {
721722 } );
722723 context .run (task );
723724 return result ;
724- } , true );
725+ });
725726 }
726727
727728 /**
@@ -762,7 +763,7 @@ public static Task<Void> action(final String desc, final Action action) {
762763 return async (desc , () -> {
763764 action .run ();
764765 return Promises .VOID ;
765- } , false );
766+ });
766767 }
767768
768769 /**
@@ -920,29 +921,26 @@ public static <T> Task<T> callable(final Callable<? extends T> callable) {
920921 * @param name a name that describes the task, it will show up in a trace
921922 * @param callable a callable to execute when this task is run, it must return
922923 * a {@code Promise<T>}
923- * @param systemHidden flag that specifies whether trace of this task will have
924- * a system-hidden flag set
925924 * @return a new task that will invoke the callable and complete with result
926925 * returned by a {@code Promise} returned by it
927926 * @see Promise
928927 */
929- public static <T > Task <T > async (final String name , final Callable <Promise <? extends T >> callable ,
930- final boolean systemHidden ) {
928+ public static <T > Task <T > async (final String name , final Callable <Promise <? extends T >> callable ) {
931929 return async (name , context -> {
932930 try {
933931 return callable .call ();
934932 } catch (Throwable e ) {
935933 return Promises .error (e );
936934 }
937- } , systemHidden );
935+ });
938936 }
939937
940938 /**
941- * Equivalent to {@code async("async", callable, systemHidden )}.
942- * @see #async(String, Callable, boolean )
939+ * Equivalent to {@code async("async", callable)}.
940+ * @see #async(String, Callable)
943941 */
944- public static <T > Task <T > async (final Callable <Promise <? extends T >> callable , final boolean systemHidden ) {
945- return async ("async" , callable , systemHidden );
942+ public static <T > Task <T > async (final Callable <Promise <? extends T >> callable ) {
943+ return async ("async" , callable );
946944 }
947945
948946 /**
@@ -957,15 +955,12 @@ public static <T> Task<T> async(final Callable<Promise<? extends T>> callable, f
957955 * @param name a name that describes the task, it will show up in a trace
958956 * @param func a function to execute when this task is run, it must return
959957 * a {@code Promise<T>}
960- * @param systemHidden flag that specifies whether trace of this task will have
961- * a system-hidden flag set
962958 * @return a new task that will invoke the function and complete with result
963959 * returned by a {@code Promise} returned by it
964960 * @see Context
965961 * @see Promise
966962 */
967- public static <T > Task <T > async (final String name , final Function1 <Context , Promise <? extends T >> func ,
968- final boolean systemHidden ) {
963+ public static <T > Task <T > async (final String name , final Function1 <Context , Promise <? extends T >> func ) {
969964 ArgumentUtil .requireNotNull (func , "function" );
970965
971966 Task <T > task = new BaseTask <T >(name ) {
@@ -975,17 +970,15 @@ protected Promise<? extends T> run(Context context) throws Throwable {
975970 }
976971 };
977972
978- task .getShallowTraceBuilder ().setSystemHidden (systemHidden );
979-
980973 return task ;
981974 }
982975
983976 /**
984- * Equivalent to {@code async("async", func, systemHidden )}.
977+ * Equivalent to {@code async("async", func)}.
985978 * @see #async(String, Function1, boolean)
986979 */
987- public static <T > Task <T > async (final Function1 <Context , Promise <? extends T >> func , final boolean systemHidden ) {
988- return async ("async" , func , systemHidden );
980+ public static <T > Task <T > async (final Function1 <Context , Promise <? extends T >> func ) {
981+ return async ("async" , func );
989982 }
990983
991984 /**
@@ -1016,7 +1009,7 @@ public static <T> Task<T> blocking(final String name, final Callable<? extends T
10161009 }
10171010 } );
10181011 return promise ;
1019- } , false );
1012+ });
10201013 }
10211014
10221015 /**
0 commit comments