Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/906d0008cdf1f02f706c to your computer and use it in GitHub Desktop.
Save nolanlawson/906d0008cdf1f02f706c to your computer and use it in GitHub Desktop.

Tests simultaneous DB access for IndexedDB

<!DOCTYPE html>
<html lang="en">
<body>
<pre id="output"></pre>
<script src="index.js"></script>
</body>
</html>
var pre = document.getElementById('output')
function log(msg) {
pre.innerHTML = pre.innerHTML + msg + "\n";
}
function openDB1() {
var req = indexedDB.open('mydb', 1);
req.onupgradeneeded = function (e) {
log('successfully upgraded db #1');
};
req.onsuccess = function (e) {
log('successfully opened db #1');
openDB2();
};
req.onerror = function(e) {
log('error on db #1: ' + e);
}
}
function openDB2() {
var req = indexedDB.open('mydb', 1);
req.onupgradeneeded = function (e) {
log('successfully upgraded db #2');
};
req.onsuccess = function (e) {
log('successfully opened db #2');
};
req.onerror = function(e) {
log('error on db #2: ' + e);
}
}
openDB1();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment