Page History
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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 | ||||||
---|---|---|---|---|---|---|
| ||||||
//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"); |
...