Skip to content

Commit

Permalink
solution?
Browse files Browse the repository at this point in the history
  • Loading branch information
Motiejukaas committed Nov 14, 2023
1 parent ad0a7ae commit a826d31
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public AnswerSubmittedEventHandlerQuizUpdater(IServiceProvider serviceProvider)
_serviceProvider = serviceProvider;
}

private async Task UpdateQuizData(object sender, AnswerSubmittedEventArgs args)
private async Task UpdateQuizDataAsync(object sender, AnswerSubmittedEventArgs args)
{
using var scope = _serviceProvider.CreateScope();
var repo = scope.ServiceProvider.GetService<IQuizRepository>();
Expand All @@ -22,7 +22,12 @@ private async Task UpdateQuizData(object sender, AnswerSubmittedEventArgs args)
await repo?.SaveAsync();
}
}


private void UpdateQuizData(object sender, AnswerSubmittedEventArgs args)
{
_ = UpdateQuizDataAsync(sender, args);
}

public override void RegisterEventHandler()
{
AnswerSubmittedEvent.Event += UpdateQuizData;
Expand Down
2 changes: 2 additions & 0 deletions QuizAppApi/QuizAppApi/Repositories/QuizRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public QuizRepository(QuizContext context)
public async Task<IEnumerable<Quiz>> GetQuizzesAsync()

Check warning on line 24 in QuizAppApi/QuizAppApi/Repositories/QuizRepository.cs

View workflow job for this annotation

GitHub Actions / build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
return _context.Quizzes;
// return await _context.Quizzes.ToListAsync();
//works fine without this, but the compiler threw a warning that return _context.Quizzes; is synchronous
}

public async Task<Quiz?> GetQuizByIdAsync(int id)
Expand Down

0 comments on commit a826d31

Please sign in to comment.