Tests simultaneous DB access for IndexedDB
Last active
August 29, 2015 14:00
-
-
Save nolanlawson/906d0008cdf1f02f706c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<body> | |
<pre id="output"></pre> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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