Deprecated the after pattern supporting methods which accept a value of Future or CompletionStage. (#25817)

This commit is contained in:
kerr 2019-03-15 17:11:55 +08:00 committed by Johan Andrén
parent 38b8c08640
commit 7649264998
4 changed files with 20 additions and 10 deletions

View file

@ -287,14 +287,13 @@ public class PatternsTest extends JUnitSuite {
@Test(expected = IllegalStateException.class)
public void testAfterFailedFuture() throws Exception {
Future<String> failedFuture = Futures.failed(new IllegalStateException("Illegal!"));
Future<String> delayedFuture =
Patterns.after(
scala.concurrent.duration.Duration.create(200, "millis"),
system.scheduler(),
ec,
failedFuture);
() -> Futures.failed(new IllegalStateException("Illegal!")));
Future<String> resultFuture = Futures.firstCompletedOf(Arrays.asList(delayedFuture), ec);
Await.result(resultFuture, FiniteDuration.apply(3, SECONDS));
@ -326,7 +325,7 @@ public class PatternsTest extends JUnitSuite {
scala.concurrent.duration.Duration.create(200, "millis"),
system.scheduler(),
ec,
Futures.successful(expected));
() -> Futures.successful(expected));
Future<String> resultFuture = Futures.firstCompletedOf(Arrays.asList(delayedFuture), ec);
@ -343,7 +342,7 @@ public class PatternsTest extends JUnitSuite {
scala.concurrent.duration.Duration.create(200, "millis"),
system.scheduler(),
ec,
Futures.successful("world"));
() -> Futures.successful("world"));
Future<String> immediateFuture = Futures.future(() -> expected, ec);
@ -408,7 +407,11 @@ public class PatternsTest extends JUnitSuite {
final CompletionStage<String> f = CompletableFuture.completedFuture(expected);
CompletionStage<String> delayedStage =
Patterns.after(Duration.ofMillis(200), system.scheduler(), ec, f);
Patterns.after(
Duration.ofMillis(200),
system.scheduler(),
ec,
() -> CompletableFuture.completedFuture(expected));
final String actual = delayedStage.toCompletableFuture().get(3, SECONDS);
assertEquals(expected, actual);
@ -421,7 +424,11 @@ public class PatternsTest extends JUnitSuite {
final CompletionStage<String> f = CompletableFuture.completedFuture("world!");
CompletionStage<String> delayedStage =
Patterns.after(Duration.ofMillis(200), system.scheduler(), ec, f);
Patterns.after(
Duration.ofMillis(200),
system.scheduler(),
ec,
() -> CompletableFuture.completedFuture("world!"));
CompletableFuture<String> immediateStage = CompletableFuture.completedFuture(expected);
CompletableFuture<Object> resultStage =

View file

@ -431,6 +431,7 @@ object Patterns {
* Returns a [[scala.concurrent.Future]] that will be completed with the success or failure of the provided Callable
* after the specified duration.
*/
@deprecated("Use the overload one which accepts a Callable of Future instead.", since = "2.5.22")
def after[T](duration: FiniteDuration, scheduler: Scheduler, context: ExecutionContext, value: Future[T]): Future[T] =
scalaAfter(duration, scheduler)(value)(context)
@ -438,6 +439,7 @@ object Patterns {
* Returns a [[java.util.concurrent.CompletionStage]] that will be completed with the success or failure of the provided value
* after the specified duration.
*/
@deprecated("Use the overloaded one which accepts a Callable of CompletionStage instead.", since = "2.5.22")
def after[T](duration: java.time.Duration,
scheduler: Scheduler,
context: ExecutionContext,
@ -871,7 +873,8 @@ object PatternsCS {
* Returns a [[java.util.concurrent.CompletionStage]] that will be completed with the success or failure of the provided value
* after the specified duration.
*/
@deprecated("Use the overloaded one which accepts java.time.Duration instead.", since = "2.5.12")
@deprecated("Use Patterns.after which accepts java.time.Duration and Callable of CompletionStage instead.",
since = "2.5.22")
def after[T](duration: FiniteDuration,
scheduler: Scheduler,
context: ExecutionContext,
@ -882,7 +885,8 @@ object PatternsCS {
* Returns a [[java.util.concurrent.CompletionStage]] that will be completed with the success or failure of the provided value
* after the specified duration.
*/
@deprecated("Use Patterns.after instead.", since = "2.5.19")
@deprecated("Use Patterns.after which accepts java.time.Duration and Callable of CompletionStage instead.",
since = "2.5.22")
def after[T](duration: java.time.Duration,
scheduler: Scheduler,
context: ExecutionContext,

View file

@ -637,7 +637,6 @@ public class FutureDocTest extends AbstractJavaTest {
public void useOnOnComplete() throws Exception {
{
Future<String> future = Futures.successful("foo");
// #onComplete
final ExecutionContext ec = system.dispatcher();

View file

@ -205,7 +205,7 @@ public class StreamTestKitDocTest extends AbstractJavaTest {
Duration.ofMillis(10),
system.scheduler(),
system.dispatcher(),
CompletableFuture.completedFuture(sleep)));
() -> CompletableFuture.completedFuture(sleep)));
final Pair<TestPublisher.Probe<Integer>, TestSubscriber.Probe<Integer>> pubAndSub =
TestSource.<Integer>probe(system)