Jörn Horstmann
Jörn Horstmann

Reputation: 34014

Doubts about HTML5 IndexedDB Async API

While reading the HTML5 IndexedDB Specification I had some doubts about its asynchronous request model. When looking at the request api example, the open method is used to start an async request.

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

At the time this request is started, there are no event handlers defined yet.

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

db.open('AddressBook', 'Address Book', {
    onsuccess: function(e) { ... },
    onerror  : function(e) { ... }
});

Upvotes: 8

Views: 1041

Answers (1)

qfel13
qfel13

Reputation: 141

There will be no race condition because JavaScript engine will finish executing actual scope (function) and then fire any callback or event handler. Read following comment on Mozilla Hacks.

Upvotes: 6

Related Questions