Versions Compared

Key

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

...

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");


JAVA와 C#코드가 흡사합니다. 복합된 비동기처리를 위한 방식은 여러가지 방법이 있겠으나

위와같이 람다식을 활용하는 방식이 진보된 방식입니다. 


Promice (미래를 위한 약속)

퓨쳐가 읽기전용 용기라고하면, 퓨쳐자체를 반환하는것을 작성하고 싶을때는 Promice를 사용합니다.

...