Doubts in the HTML5 IndexedDB Async API

While reading the HTML5 IndexedDB specification , I had some doubts about its asynchronous request model. When viewing a request api example, the open method is used to run an asynchronous request.

 var request = indexedDB.open('AddressBook', 'Address Book'); request.onsuccess = function(evt) {...}; request.onerror = function(evt) {...}; 

While this request is running, event handlers have not yet been defined.

  • Isn't that a race condition?
  • What happens when the open method is executed before the javascript interpreter performs the onsuccess assignment?
  • Or did the request really start only after registering both callbacks?

In my opinion, api, like the following, would be much more logical:

 db.open('AddressBook', 'Address Book', { onsuccess: function(e) { ... }, onerror : function(e) { ... } }); 
+6
javascript html5 asynchronous
source share
1 answer

There will be no race condition, because the JavaScript engine will complete the execution of the actual scope (function) and then fire any callback or event handler. Read the comment below at Mozilla Hacks.

+5
source share

All Articles