Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

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