bminer / node-mysql-queues

Wraps 'node-mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.
MIT License
92 stars 11 forks source link

Limitation: Asynchronous calls in a query callback #3

Closed bminer closed 12 years ago

bminer commented 12 years ago

For example, you can't do something like this...

//You may be tempted to do this...
var fs = require('fs');
var trans = db.startTransaction();
trans.query("INSERT ...", [...], function(err, info) {
    fs.readFile("foobar.txt", function(err, data) {
        //By now, it's too late to use `trans`
        if(data == "something")
            trans.commit();
        else
            trans.rollback();
    });
    //The query callback is now done!! This is your last chance
    //to call `commit` or `rollback`
}).execute();

Maybe implement Queue.pause() and Queue.resume() functions?

bminer commented 12 years ago

Fixed in version 0.3.0