Forum BigDB Wait On type feature for BigDB?

Discussion and help relating to the PlayerIO database solution, BigDB.

Wait On type feature for BigDB?

Postby moosemouse » July 15th, 2011, 6:25 am

I am no expert on databases, so I may be really missing some concepts. But the asynchronous nature of BigDB often causes me headaches. Most of the time when I load something from BigDB my code depends on the result to proceed. I am aware that I can put the continuation of the code in the BigDB loader's callback, but this really obfuscates the code's flow. Is there a simple/elegant way to make the code wait on the result of the BigDB call to proceed?

Thanks!
Shawn
User avatar
moosemouse
Paid Member
 
Posts: 83
Joined: August 11th, 2010, 2:51 pm
Location: New Albany, Ohio USA

Re: Wait On type feature for BigDB?

Postby wildbunny » July 19th, 2011, 8:03 pm

moosemouse wrote:I am no expert on databases, so I may be really missing some concepts. But the asynchronous nature of BigDB often causes me headaches. Most of the time when I load something from BigDB my code depends on the result to proceed. I am aware that I can put the continuation of the code in the BigDB loader's callback, but this really obfuscates the code's flow. Is there a simple/elegant way to make the code wait on the result of the BigDB call to proceed?

Thanks!
Shawn


Afraid not - it can be mitigated using delegates and lambdas... Are you using them already?

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: Wait On type feature for BigDB?

Postby moosemouse » July 19th, 2011, 8:29 pm

Thanks for the info, Paul. To be honest, I don't really know what you are talking about. But you have given me some good new directions to Google in :D

Thanks,
Shawn
User avatar
moosemouse
Paid Member
 
Posts: 83
Joined: August 11th, 2010, 2:51 pm
Location: New Albany, Ohio USA

Re: Wait On type feature for BigDB?

Postby wildbunny » July 19th, 2011, 8:36 pm

moosemouse wrote:Thanks for the info, Paul. To be honest, I don't really know what you are talking about. But you have given me some good new directions to Google in :D

Thanks,
Shawn


I can give you a neat example to demonstrate it :)

Code: Select all
public void CreateOverwriteObject(string table, string key, DatabaseObject dbo, Action successAction)
{
   this.PlayerIO.BigDB.DeleteKeys(table, new string[] { key }, () =>
   {
      this.PlayerIO.BigDB.CreateObject(table, key, dbo, resultDbo =>
      {
         successAction();
      }, OnDatabaseError);
   }, OnDatabaseError);
}


In this example I'm using lambda functions ()=>{} for the callbacks which makes the code much nicer to write. It takes a little bit to get used to using them, but they're very cool :)

Cheers, Paul.
wildbunny
 
Posts: 217
Joined: March 9th, 2011, 10:35 am

Re: Wait On type feature for BigDB?

Postby moosemouse » July 19th, 2011, 9:17 pm

Cool, I will test it out!
User avatar
moosemouse
Paid Member
 
Posts: 83
Joined: August 11th, 2010, 2:51 pm
Location: New Albany, Ohio USA


Return to BigDB