javascript - PARSE - Handling concurrent requests? -


i've created turn based drawing game using parse can potentially play anyone. 1 user @ time can play. there 3 turns. it's working fine within player's friend list -> either start new game, or receive notification continue one.

i'm trying implement multiplayer mode -> have seperate list in database available public games. if game made public, create new object in list pointer game. every time user searches available game, queries list, if record found, delete public game object in particular list make unavailable other users, , game goes on..

i'm wondering following -> how parse handle concurrent requests? possible multiple users, searching @ same time, try delete same object (see code below)? i'm skipping random index in query avoid such behaviour seems trivial..

here sample of cloud code handling request:

parse.cloud.define('findpublicgame', function(req, res) {     var query = new parse.query("public");     query.count({         success: function(number) {             if (number == 0) {                 // no public games - reject                 res.success(number);             } else {                 // public game found - handle                 query.limit(1)                 var randomindex = parseint(math.random() * number);                 query.skip(randomindex);                 query.find({                     success: function(object) {                         // delete public                         object[0].destroy({                             success: function(_data) {                                 res.success(_data);                             },                             error: function(error) {                                 res.error();                             }                         });                     },                     error: function(error, object) {                         res.error(error);                     }                 });             }         },         error: function(error) {             res.error(error);         }     }); }); 

is correct assume trying destroy already-destroyed object result in error?

i had idea of adding beforedelete function on public game object, check if it's still available, i'm trying keep number of requests low now..

if enlighten me, kudos!

is correct assume trying destroy already-destroyed object result in error?

in experience, no, not correct. used delete methods available directly in android , ios apis rather calling method in parse cloud, delete methods in both android , ios apis, calling delete on deleted object not throw error. proceeds if delete successful.

i had idea of adding beforedelete function on public game object, check if it's still available, i'm trying keep number of requests low now..

this best option have. typically, you're dealing "object modification" check "modified at" timestamp, since deleting objects, need check whether still exists or not.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -