Created
September 29, 2010 01:18
-
-
Save rwaldron/602138 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
<html> | |
<head> | |
<script> | |
var worker = new Worker('worker.js'); | |
worker.addEventListener('message', function (event) { | |
console.log(event.data); | |
}); | |
</script> | |
</head> | |
<body> | |
Foo | |
</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 db = openDatabaseSync("WorkerFoo", "", "", 1), | |
results = []; | |
//if(db) postMessage('Web Worker DB Built'); | |
db.transaction( function(tx) { | |
tx.executeSql('CREATE TABLE IF NOT EXISTS foos (id REAL UNIQUE, label TEXT, timestamp REAL)'); | |
}); | |
//if(db) postMessage('Table Created'); | |
db.transaction( function(tx) { | |
tx.executeSql("INSERT INTO foos (label, timestamp) values(?, ?)", ['Foo!', new Date().getTime() ], null, null); | |
}); | |
//if(db) postMessage('Data Inserted'); | |
db.transaction( function(tx){ | |
var result = tx.executeSql('SELECT * FROM foos'), | |
len = result.rows.length, i; | |
for (i = 0; i < len; i++) { | |
results[results.length] = result.rows.item(i); | |
} | |
}); | |
postMessage(results); |
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 db = openDatabase("WorkerFoo", "", "", 1), | |
results = []; | |
//if(db) postMessage('Web Worker DB Built'); | |
db.transaction( function(tx) { | |
tx.executeSql('CREATE TABLE IF NOT EXISTS foos (id REAL UNIQUE, label TEXT, timestamp REAL)', [], function (tx, result) { | |
postMessage(result) | |
}, function (tx, error) { | |
postMessage(error) | |
}); | |
}); | |
//if(db) postMessage('Table Created'); | |
db.transaction( function(tx) { | |
tx.executeSql("INSERT INTO foos (label, timestamp) values(?, ?)", ['Foo!', new Date().getTime() ], null, null); | |
}); | |
//if(db) postMessage('Data Inserted'); | |
db.transaction( function(tx){ | |
tx.executeSql('SELECT * FROM foos', [], function (tx, resultset) { | |
var len = resultset.rows.length, i; | |
for (i = 0; i < len; i++) { | |
results[results.length] = resultset.rows.item(i); | |
} | |
}); | |
}); | |
postMessage(results); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment