Versions Compared

Key

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

...

Code Block
languagescala
themeEmacs
titleFuture를 사용
var request = EventRequest(ticketNr)    //요청을만든다
val futureRoute : Future[Route] = Future{
  callEventService(request).event
}.map{ event =>
  val trafficRequest = TrafficRequest{
    destination = event.location,
    arrivalTime = event.time
  )
  callTrafficeService(trafficRequest).route  //교통 루트를 반환한다.
}


Future Sample

...

Ff963556.dda12864-f9bd-4340-831f-212c4ee8bc4a(en-us,PandP.10).png

Code Block
languagejava
themeEmacs
titleJAVA
Integer input=1;
CompletableFuture<Integer> futureB  
  = CompletableFuture.supplyAsync(() -> input+1 );

CompletableFuture<Integer> futureC  
= CompletableFuture.supplyAsync(() -> input+1+2 );

CompletableFuture<Void> combinedFuture 
  = CompletableFuture.allOf(futureB, futureC);

combinedFuture.get();

Integer result = futureB.get() + futureC.get();		
System.out.println(result);
Code Block
languagec#
themeEmacs
titleC#
//Labda
Func<int, int> F1 = x => x + 1;
Func<int, int> F2 = x => x + 1;
Func<int, int> F3 = x => x + 1;
Func<int, int, int> F4 = delegate ( int x, int y ){
     return x + y;
};            

//Block with task
Task<int> futureA = Task.Factory.StartNew<int>(() => F1(1));
int c = F2(1);
int d = F3(c);
int f = F4(futureA.Result, d);
Console.WriteLine("ResultA:" + f);

//Continuation Tasks
var futureB = Task.Factory.StartNew<int>(() => F1(1));
var futureD = Task.Factory.StartNew<int>(() => F3(F2(1)));
var futureF = Task.Factory.ContinueWhenAll<int, int>(
                 new[] { futureB, futureD },
                 ( tasks ) => F4(futureB.Result, futureD.Result));

futureF.ContinueWith(( t ) =>
    Console.WriteLine("ResultF:" + t.Result)
);

Console.WriteLine("Code...End");

...