Skip to content

MediatR async handlers without await #141

@afoxtrident

Description

@afoxtrident

Ask a question

Hello,

If you have a create command without any return type the method is generated as async, however doesn't await or complete any task (as below)

public async Task Handle(CreateItemCommand request, CancellationToken cancellationToken)
{
    var item= new Item
    {
        Id = request.Id,
        Value = request.Value
    };

    _repository.Add(item);
}

Would it be possible to change methods like these to remove the async keyword, and return Task.CompletedTask ?

According to AI benchmarks its considerably quicker if we return a task.

Image

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions