I want to call the following code:
public async ValueTask UserGivenClaim(AppUser user, Organization org, string claim)
{
var notify = new NotifyClaims(user, org);
await notify.SetReplyToTask(null, org);
await NotificationQueue.PushValueTask(notify);
}
In the code above SetReplyToTask()
returns a Task and PushValueTask()
returns a ValueTask. And from a performance point of view SetReplyToTask()
99% of the time does an if check that’s true and returns. So 99% of the time it is not calling Task methods inside of it.
Declaring UserGivenClaim
async lets me call await notify.SetReplyToTask(null, org);
But I’m not sure how to call NotificationQueue.PushValueTask(notify);
in this situation.
The other possibility is to make notify.SetReplyToTask()
a ValueTask. If 99% of the time it is not calling a Task, is this when I should be using ValueTask?