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) { ... } });
javascript html5 asynchronous
JΓΆrn horstmann
source share