/** * Equivalent to {@code andThen("andThen", consumer)}. * @see #andThen(String, Consumer3) */ default Tuple3Task<T1, T2, T3> andThen(final Consumer3<T1, T2, T3> consumer) { return cast(andThen("andThen: " + _taskDescriptor.getDescription(consumer.getClass().getName()), tuple -> consumer.accept(tuple._1(), tuple._2(), tuple._3()))); }
@Override protected void doRunExample(final Engine engine) throws Exception { final MockService<String> httpClient = getService(); final Task<String> fetchBing = fetchUrl(httpClient, "http://www.bing.com"); final Task<String> fetchYahoo = fetchUrl(httpClient, "http://www.yahoo.com"); final Task<String> fetchGoogle = fetchUrl(httpClient, "http://www.google.com"); final Task<?> fanIn = Task.par(fetchBing, fetchGoogle, fetchYahoo) .andThen((bing, google, yahoo) -> { System.out.println("Bing => " + bing); System.out.println("Yahoo => " + yahoo); System.out.println("Google => " + google); }); engine.run(fanIn); fanIn.await(); printTracingResults(fanIn); } }
@Test public void testPar3AndThen() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3)).andThen((a, b, c) -> value.set(a + b + c)); runAndWait("TestTaskFactoryMethods.testPar3AndThen", task); assertEquals(value.get(), 1 + 2 + 3); assertEquals(countTasks(task.getTrace()), 2 + 1 + 3); }
@Test public void testPar3AndThenDsc() { AtomicInteger value = new AtomicInteger(); Task<?> task = Task.par(Task.value(1), Task.value(2), Task.value(3)).andThen("test", (a, b, c) -> value.set(a + b + c)); runAndWait("TestTaskFactoryMethods.testPar3AndThenDsc", task); assertEquals(value.get(), 1 + 2 + 3); assertEquals(countTasks(task.getTrace()), 2 + 1 + 3); }
return cast(andThen(desc, tuple -> consumer.accept(tuple._1(), tuple._2(), tuple._3())));
/** * Equivalent to {@code andThen("andThen", consumer)}. * @see #andThen(String, Consumer3) */ default Tuple3Task<T1, T2, T3> andThen(final Consumer3<T1, T2, T3> consumer) { return cast(andThen("andThen: " + _taskDescriptor.getDescription(consumer.getClass().getName()), tuple -> consumer.accept(tuple._1(), tuple._2(), tuple._3()))); }
return cast(andThen(desc, tuple -> consumer.accept(tuple._1(), tuple._2(), tuple._3())));
/** * Performs three "slow" tasks and collects the results. This returns a task and lets * the RestLi server invoke it. * * @return concatenation of binary representation of a, all caps of b, and string value * of c */ @Action(name = "parseq3") public Task<String> parseqAction3(@ActionParam("a") final int a, @ActionParam("b") final String b, @ActionParam("c") final boolean c) { final Task<String> t1 = makeTaskA(a); final Task<String> t2 = makeTaskB(b); final Task<String> t3 = makeTaskC(c); final Task<String> collect = makeConcatTask(t1, t2, t3); return Task.par(t1, t2, t3).andThen(collect); }