■ Task 클래스의 CompletedTask 속성을 사용하는 방법을 보여준다
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
using System; using System.Threading.Tasks; private static void Execute(int count) { for(int i = 0; i < count; i++) { Console.WriteLine(i + 1); } } private static Task ExecuteAsync(int count) { try { Execute(count); return Task.CompletedTask; } catch(Exception exception) { return Task.FromException(exception); } } |