Skip to content
This repository has been archived by the owner on Mar 6, 2018. It is now read-only.

Commit

Permalink
Force Hive session creation to be done on a background thread (#191)
Browse files Browse the repository at this point in the history
Previously it was possible to hit SessionPutAsync via a coroutine, which would stall the main thread.  This is just the first of many places where we probably need to guard API calls in Task.Run to ensure that the HTTP request work gets done on a background thread instead.
  • Loading branch information
hach-que committed Jun 3, 2017
1 parent 31f2591 commit 5af9c8a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Protogame/Hive/DefaultHiveSessionManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ public async Task<TempSessionWithSecrets> CreateTemporarySession()
{
Init();

var session = await _temporarySessionApi.SessionPutAsync();
_tempSessions.Add(session);
return session;
// Ensure this does not run as part of a coroutine - force it to
// a background thread with Task.Run.
return await Task.Run(async () =>
{
var session = await _temporarySessionApi.SessionPutAsync();
_tempSessions.Add(session);
return session;
});
}

public IReadOnlyCollection<TempSessionWithSecrets> ActiveTemporarySessions => _tempSessions.AsReadOnly();
Expand Down

0 comments on commit 5af9c8a

Please sign in to comment.