1- using System . Diagnostics . CodeAnalysis ;
2- using System . Runtime . CompilerServices ;
3- using System . Runtime . InteropServices ;
1+ using System . Runtime . InteropServices ;
42
53namespace DotNext . Threading . Tasks ;
64
@@ -37,41 +35,31 @@ public static implicit operator ValueTask(CompletedTask task)
3735[ StructLayout ( LayoutKind . Auto ) ]
3836internal readonly struct CompletedTask < T >
3937{
40- private readonly Exception ? failure ;
41-
42- [ AllowNull ]
43- private readonly T result ;
38+ private readonly Result < T > result ;
4439
4540 /// <summary>
4641 /// Creates task that has completed with a specified exception.
4742 /// </summary>
4843 /// <param name="failure">The exception with which to complete the task.</param>
49- public CompletedTask ( Exception failure ) => this . failure = failure ;
44+ public CompletedTask ( Exception failure ) => result = new ( failure ) ;
5045
5146 /// <summary>
5247 /// Creates task that has completed successfully with a specified result.
5348 /// </summary>
5449 /// <param name="result">The task result.</param>
55- public CompletedTask ( T result ) => this . result = result ;
50+ public CompletedTask ( T result ) => this . result = new ( result ) ;
5651
5752 /// <summary>
5853 /// Obtains <see cref="Task{TResult}"/> completed synchronously.
5954 /// </summary>
6055 /// <param name="task">Completed task.</param>
6156 public static implicit operator Task < T > ( CompletedTask < T > task )
62- => task . failure is null ? Task . FromResult ( task . result ) : Task . FromException < T > ( task . failure ) ;
57+ => task . result . AsTask ( ) ;
6358
6459 /// <summary>
6560 /// Obtains <see cref="ValueTask{TResult}"/> completed synchronously.
6661 /// </summary>
6762 /// <param name="task">Completed task.</param>
6863 public static implicit operator ValueTask < T > ( CompletedTask < T > task )
69- {
70- var builder = AsyncValueTaskMethodBuilder < T > . Create ( ) ;
71- if ( task . failure is null )
72- builder . SetResult ( task . result ) ;
73- else
74- builder . SetException ( task . failure ) ;
75- return builder . Task ;
76- }
64+ => new ( task . result . AsTask ( ) ) ;
7765}
0 commit comments