Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
themeEmacs
@FunctionalInterface
interface FuncB {
    public int calc(int a, int b);
}
 
@FunctionalInterface
interface FuncA {
    public int calc(int a);
}
 
FuncA F1 = (int a) -> a+1;
FuncA F2 = (int a) -> a+1;
FuncA F3 = (int a) -> a+1;
FuncB F4 = (int a,int b) -> a+b;
             
Integer input=1;
CompletableFuture<Integer> futureB 

        = CompletableFuture.supplyAsync(() -> F1.calc(1) );               
 
CompletableFuture<Integer> futureD
        = CompletableFuture.supplyAsync(() -> F3.calc(F2.calc(1))  );

CompletableFuture<Void> combinedFuture
          
 
CompletableFuture<Void> combinedFuture
  = CompletableFuture.allOf(futureB, futureD);
 
combinedFuture.get();       .thenAccept( r-> {
            // 최종 연산로직을 비동기로 처리한 케이스
           
 Integer resultvalue1 = futureB.getjoin() + futureD.get();        
System.out.println(result);

...

;
            Integer value2 = futureD.join();
            log( String.format("async result:%d", value1+value2 ));
        });

// 최종 연산로직을 동기처리로 변환한 예
combinedFuture.get();
Integer sresult = futureB.get() + futureD.get();
log( String.format("sync result:%d",sresult) );


Graph

일반적인 비동기 조합처리를 위해서 JAVA의 CompletetableFuture 로도 충분하지만

...