Advertisement
Frank84

BatchGet

Oct 28th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. //====================================================================//
  2. public void LoadPlayers(List<string> facebookIDs, System.Action<List<PlayerDatabaseItem>> callback)
  3. {
  4.     StartCoroutine(LoadPlayersAsync(facebookIDs, callback));
  5. }
  6. //====================================================================//
  7. // https://forums.aws.amazon.com/thread.jspa?threadID=240744
  8. // http://gamedev.stackexchange.com/questions/50864/mixing-threads-and-coroutines-in-unity3d-mobile
  9. private IEnumerator LoadPlayersAsync(List<string> facebookIDs, System.Action<List<PlayerDatabaseItem>> callback)
  10. {
  11.     bool isDone = false;
  12.     BatchGet<PlayerDatabaseItem> batchGet = null;
  13.     Thread thread = new Thread(() =>
  14.     {
  15.         // This is a synchronous call that creates another thread and waits.
  16.         // We must wait for it too inside this thread and handle the
  17.         // response within the coroutine (main thread).
  18.         batchGet = m_dynamoDBContext.CreateBatchGet<PlayerDatabaseItem>();
  19.        
  20.         isDone = true;
  21.     });
  22.     thread.Start();
  23.  
  24.     while (isDone == false)
  25.     {
  26.         yield return null;
  27.     }
  28.  
  29.     foreach (string facebookID in facebookIDs)
  30.     {
  31.         batchGet.AddKey(facebookID);
  32.     }
  33.  
  34.     batchGet.ExecuteAsync((AmazonDynamoDBResult responseObject) =>
  35.     {
  36.         if (responseObject.Exception != null)
  37.         {
  38.             Debug.Log("F84AWSManager.LoadPlayers - Failure: " + responseObject.Exception.Message);
  39.         }
  40.         else
  41.         {
  42.             if (callback != null) callback(batchGet.Results);
  43.         }
  44.     });
  45. }
  46. //====================================================================//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement