Skip to content

Commit

Permalink
Ensure initial transaction executes in nextTick
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Jul 7, 2014
1 parent 0c6b65b commit db9296c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
16 changes: 11 additions & 5 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ License for common Javascript: MIT or Apache
READ_ONLY_REGEX = /^\s*(?:drop|delete|insert|update|create)\s/i
IOS_REGEX = /iP(?:ad|hone|od)/
nextTick = window.setImmediate || (fun) ->
window.setTimeout(fun, 0)
return
- SQLitePlugin object is defined by a constructor function and prototype member functions:
SQLitePlugin = (openargs, openSuccess, openError) ->
Expand Down Expand Up @@ -59,8 +63,7 @@ License for common Javascript: MIT or Apache
SQLitePlugin::addTransaction = (t) ->
@txQ.push t
if @txQ.length is 1
t.start()
@.startNextTransaction()
return
SQLitePlugin::transaction = (fn, error, success) ->
Expand All @@ -72,9 +75,12 @@ License for common Javascript: MIT or Apache
return
SQLitePlugin::startNextTransaction = ->
@txQ.shift()
if @txQ[0]
@txQ[0].start()
tx = @
nextTick () ->
if tx.txQ.length > 0
tx.txQ.shift().start()
return
return
SQLitePlugin::open = (success, error) ->
Expand Down
17 changes: 17 additions & 0 deletions test-www/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,23 @@
});
});

test(suiteName + ' test callback order', function () {
stop();
var db = openDatabase("Database-Callback-Order", "1.0", "Demo", DEFAULT_SIZE);
var blocked = true;

db.transaction(function(tx) {
ok(!blocked, 'callback to the transaction shouldn\'t block (1)');
tx.executeSql('SELECT 1 from sqlite_master', [], function () {
ok(!blocked, 'callback to the transaction shouldn\'t block (2)');
});
}, function(err) { ok(false, err.message) }, function() {
start();
ok(!blocked, 'callback to the transaction shouldn\'t block (3)');
});
blocked = false;
});

/**
test(suiteName + "PRAGMA & multiple databases", function() {
var db = openDatabase("DB1", "1.0", "Demo", DEFAULT_SIZE);
Expand Down
21 changes: 13 additions & 8 deletions www/SQLitePlugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit db9296c

Please sign in to comment.