@@ -149,6 +149,34 @@ private static <U> DependentPromise<U> doWrap(Promise<U> original, CompletionSta
149149 return result ;
150150 }
151151
152+ public DependentPromise <T > delay (long timeout , TimeUnit unit ) {
153+ return delay (timeout , unit , true );
154+ }
155+
156+ public DependentPromise <T > delay (long timeout , TimeUnit unit , boolean delayOnError ) {
157+ return delay (timeout , unit , delayOnError , false );
158+ }
159+
160+ public DependentPromise <T > delay (long timeout , TimeUnit unit , boolean delayOnError , boolean enlistOrigin ) {
161+ return delay (Timeouts .toDuration (timeout , unit ), delayOnError , enlistOrigin );
162+ }
163+
164+ public DependentPromise <T > delay (Duration duration ) {
165+ return delay (duration , true );
166+ }
167+
168+ public DependentPromise <T > delay (Duration duration , boolean delayOnError ) {
169+ return delay (duration , delayOnError , false );
170+ }
171+
172+ public DependentPromise <T > delay (Duration duration , boolean delayOnError , boolean enlistOrigin ) {
173+ CompletablePromise <?> delayed = new CompletablePromise <>();
174+ whenComplete (Timeouts .configureDelay (this , delayed , duration , delayOnError ));
175+ // Use *async to execute on default "this" executor
176+ return thenCombineAsync (
177+ delayed , (r , d ) -> r , enlistOrigin ? PromiseOrigin .ALL : PromiseOrigin .PARAM_ONLY
178+ );
179+ }
152180
153181 public DependentPromise <T > orTimeout (long timeout , TimeUnit unit ) {
154182 return orTimeout (timeout , unit , true );
@@ -159,7 +187,7 @@ public DependentPromise<T> orTimeout(long timeout, TimeUnit unit, boolean cancel
159187 }
160188
161189 public DependentPromise <T > orTimeout (long timeout , TimeUnit unit , boolean cancelOnTimeout , boolean enlistOrigin ) {
162- return orTimeout (Promises .toDuration (timeout , unit ), cancelOnTimeout , enlistOrigin );
190+ return orTimeout (Timeouts .toDuration (timeout , unit ), cancelOnTimeout , enlistOrigin );
163191 }
164192
165193 public DependentPromise <T > orTimeout (Duration duration ) {
@@ -171,11 +199,11 @@ public DependentPromise<T> orTimeout(Duration duration, boolean cancelOnTimeout)
171199 }
172200
173201 public DependentPromise <T > orTimeout (Duration duration , boolean cancelOnTimeout , boolean enlistOrigin ) {
174- Promise <T > onTimeout = Promises .failAfter (duration );
202+ Promise <T > onTimeout = Timeouts .failAfter (duration );
175203 // Use *async to execute on default "this" executor
176204 DependentPromise <T > result = this
177205 .applyToEitherAsync (onTimeout , Function .identity (), enlistOrigin ? PromiseOrigin .ALL : PromiseOrigin .PARAM_ONLY );
178- result .whenComplete (Promises .timeoutsCleanup (this , onTimeout , cancelOnTimeout ));
206+ result .whenComplete (Timeouts .timeoutsCleanup (this , onTimeout , cancelOnTimeout ));
179207 return result ;
180208 }
181209
@@ -188,7 +216,7 @@ public DependentPromise<T> onTimeout(T value, long timeout, TimeUnit unit, boole
188216 }
189217
190218 public DependentPromise <T > onTimeout (T value , long timeout , TimeUnit unit , boolean cancelOnTimeout , boolean enlistOrigin ) {
191- return onTimeout (value , Promises .toDuration (timeout , unit ), cancelOnTimeout , enlistOrigin );
219+ return onTimeout (value , Timeouts .toDuration (timeout , unit ), cancelOnTimeout , enlistOrigin );
192220 }
193221
194222 public DependentPromise <T > onTimeout (T value , Duration duration ) {
@@ -208,11 +236,11 @@ public DependentPromise<T> onTimeout(Supplier<? extends T> supplier, long timeou
208236 }
209237
210238 public DependentPromise <T > onTimeout (Supplier <? extends T > supplier , long timeout , TimeUnit unit , boolean cancelOnTimeout ) {
211- return onTimeout (supplier , Promises .toDuration (timeout , unit ), false );
239+ return onTimeout (supplier , Timeouts .toDuration (timeout , unit ), false );
212240 }
213241
214242 public DependentPromise <T > onTimeout (Supplier <? extends T > supplier , long timeout , TimeUnit unit , boolean cancelOnTimeout , boolean enlistOrigin ) {
215- return onTimeout (supplier , Promises .toDuration (timeout , unit ), enlistOrigin );
243+ return onTimeout (supplier , Timeouts .toDuration (timeout , unit ), enlistOrigin );
216244 }
217245
218246 public DependentPromise <T > onTimeout (Supplier <? extends T > supplier , Duration duration ) {
@@ -227,7 +255,7 @@ public DependentPromise<T> onTimeout(Supplier<? extends T> supplier, Duration du
227255 Function <T , Supplier <? extends T >> valueToSupplier = v -> () -> v ;
228256
229257 // timeout converted to supplier
230- Promise <Supplier <? extends T >> onTimeout = Promises
258+ Promise <Supplier <? extends T >> onTimeout = Timeouts
231259 .delay (duration )
232260 .dependent ()
233261 .thenApply (d -> supplier , true );
@@ -238,7 +266,7 @@ public DependentPromise<T> onTimeout(Supplier<? extends T> supplier, Duration du
238266 // Use *async to execute on default "this" executor
239267 .applyToEitherAsync (onTimeout , Supplier ::get , PromiseOrigin .ALL );
240268
241- result .whenComplete (Promises .timeoutsCleanup (this , onTimeout , cancelOnTimeout ));
269+ result .whenComplete (Timeouts .timeoutsCleanup (this , onTimeout , cancelOnTimeout ));
242270 return result ;
243271 }
244272
0 commit comments