Skip to content

Commit

Permalink
#218 - Sync parallel queries for profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Feb 22, 2019
1 parent a70fde4 commit b1ca38f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Money.UI.Blazor/Services/UserMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,32 @@ internal class UserMiddleware : HttpQueryDispatcher.IMiddleware,
IEventHandler<EmailChanged>
{
private ProfileModel profile;
private Task getProfileTask;

public async Task<object> ExecuteAsync(object query, HttpQueryDispatcher dispatcher, HttpQueryDispatcher.Next next)
{
if (query is GetProfile)
if (query is GetProfile getProfile)
{
if (profile == null)
profile = (ProfileModel)await next(query);
{
if (getProfileTask == null)
getProfileTask = LoadProfileAsync(getProfile, next);

await getProfileTask;
getProfileTask = null;
}

return profile;
}

return await next(query);
}

private async Task LoadProfileAsync(GetProfile query, HttpQueryDispatcher.Next next)
{
profile = (ProfileModel)await next(query);
}

Task IEventHandler<EmailChanged>.HandleAsync(EmailChanged payload)
{
if (profile != null)
Expand Down

0 comments on commit b1ca38f

Please sign in to comment.