-
-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Api renewals #5
Api renewals #5
Changes from 3 commits
7a0a30b
e143e5f
db13696
3cc1b45
8efec9e
fc69347
865d091
910ba64
7d3f85b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using static System.Threading.Tasks.Task; | ||
|
||
namespace ContextFreeTasks | ||
{ | ||
[AsyncMethodBuilder(typeof(AsyncContextFreeTaskMethodBuilder))] | ||
public struct ContextFreeTask | ||
{ | ||
public Task Task { get; } | ||
public ContextFreeTask(Task t) => Task = t; | ||
private readonly Task _task; | ||
public Task Task => _task ?? FromResult(default(object)); | ||
internal ContextFreeTask(Task t) => _task = t; | ||
public ContextFreeTaskAwaiter GetAwaiter() => new ContextFreeTaskAwaiter(Task); | ||
public void Wait() => _task?.Wait(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is by design. Users should use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in my opinion, naming of 'ContextFree' includes the meaning 'This can blocking-wait safely'. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using static System.Threading.Tasks.Task; | ||
|
||
namespace ContextFreeTasks | ||
{ | ||
[AsyncMethodBuilder(typeof(AsyncContextFreeTaskMethodBuilder<>))] | ||
public struct ContextFreeTask<T> | ||
{ | ||
public Task<T> Task { get; } | ||
public ContextFreeTask(Task<T> t) => Task = t; | ||
private readonly Task<T> _task; | ||
public Task<T> Task => _task ?? FromResult(default(T)); | ||
public T Result => GetAwaiter().GetResult(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is uneasy. For consistency with |
||
internal ContextFreeTask(Task<T> t) => _task = t; | ||
public ContextFreeTaskAwaiter<T> GetAwaiter() => new ContextFreeTaskAwaiter<T>(Task); | ||
public void Wait() => _task?.Wait(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. by design, no |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far,
await
onnull
should throw an Exception. For the purpose of null-safety, the constructor should throw an exception ift
isnull
and_task
should not benull
. Of course,default(ContextFreeTask)
makes_task
benull
, but, it is misuse.I hope the following proposals:
dotnet/roslyn#7171
dotnet/roslyn#15108
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I concerned about
default(ContextFreeTask)
. if provides struct as public, we must consider the default.for example,
ValueTask
created with default keyword, it is same asFromResult(default(T))
.the constructor of
ContextFreeTask
is hid to internal. so ONLYdefault(ContextFreeTask)
makes_task
benull
. it's very rare case.