The indexedDB has a spec saying that you can access an indexed database synchronously, but it hasn't been implemented yet.
I was just wondering if there is a way to make it synchronous manually,
My JavaScript looks like this,
var trans = databaseAsync.transaction(["mapTile"], IDBTransaction.READ_WRITE);
var store = trans.objectStore("mapTile");
var keyRange = IDBKeyRange.bound(evt.data[0], evt.data[0]);
var cursorRequest = store.openCursor(keyRange);
// can you put some kind of wait in here?
cursorRequest.onsuccess = function(e)
{
var result = e.target.result;
if(!!result == false)
{
}
}
So can you put something in there to make it wait until the onsuccess method has been called before continuing on?
The reason why I want to do this is the code above is wrapped inside this method,
dojo.extend(esri.layers.ArcGISTiledMapServiceLayer, {
getTileUrl : function(level, row, col)
{
// blah
return url;
}
So it is an ESRI tile layer (which will load tiles onto a map on my web page), and that method needs to return the url straight away for a particular tile. It will either be a URL to load the image from if it isn't cached in the database already, or this,
data:image;base64,*BASE64DATA*
Where BASE64DATA is the data from the database if previously cached.
I was previously using the localStorage for this, which works synchronously, but that has a 5MB limit so I thought I would experiment with indexedDB.
Synchronous and asynchronousOperations performed using IndexedDB are done asynchronously, so as not to block applications.
Before creating the database I want to tell you about the two API modes of IndexedDB. Synchronous mode: This mode was created to be used only in conjunction with web workers. But most browsers currently do not support the synchronous mode.
Note: IndexedDB can be used inside a service worker for data storage if you require it.
IndexedDB Sync API is marked as a risky part of the IndexedDB specification and they might be removed due to potential lack of implementations.
I've implemented 'sync' solution using the 'oncomplete' transaction event which guaranties that the current action is finished before starting the next one, and I also use custom semaphore and queue logic which handles the async calls from GUI and ensures that 2 open connections towards IndexedDB database won't happen at the same time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With