Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //====================================================================//
- public void LoadPlayers(List<string> facebookIDs, System.Action<List<PlayerDatabaseItem>> callback)
- {
- StartCoroutine(LoadPlayersAsync(facebookIDs, callback));
- }
- //====================================================================//
- // https://forums.aws.amazon.com/thread.jspa?threadID=240744
- // http://gamedev.stackexchange.com/questions/50864/mixing-threads-and-coroutines-in-unity3d-mobile
- private IEnumerator LoadPlayersAsync(List<string> facebookIDs, System.Action<List<PlayerDatabaseItem>> callback)
- {
- bool isDone = false;
- BatchGet<PlayerDatabaseItem> batchGet = null;
- Thread thread = new Thread(() =>
- {
- // This is a synchronous call that creates another thread and waits.
- // We must wait for it too inside this thread and handle the
- // response within the coroutine (main thread).
- batchGet = m_dynamoDBContext.CreateBatchGet<PlayerDatabaseItem>();
- isDone = true;
- });
- thread.Start();
- while (isDone == false)
- {
- yield return null;
- }
- foreach (string facebookID in facebookIDs)
- {
- batchGet.AddKey(facebookID);
- }
- batchGet.ExecuteAsync((AmazonDynamoDBResult responseObject) =>
- {
- if (responseObject.Exception != null)
- {
- Debug.Log("F84AWSManager.LoadPlayers - Failure: " + responseObject.Exception.Message);
- }
- else
- {
- if (callback != null) callback(batchGet.Results);
- }
- });
- }
- //====================================================================//
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement