0

I'm tired of these callback trees in azure mobile services. So I would like to wrap things like mssql.query(sql, params, options) with the help of a promise library like Kris Kowal's Q. In that way it would be very easy to get fulfillments via the then function.

Currently I don't succeed in doing this:

Error: [Error: Invalid callback options passed to 'query'. Callback options must be an object with at least one 'success' or 'error' property of type 'function' or a systemProperties property of type 'Array'.]

For core nodejs functions like fs.readFile Q.denodeify works, but I suppose this has to deal with the way the callbacks are defined. In mobile services they use an object literal with a succes and error properties just like the above error log indicates:

mssql.query(sql, sqlParams, {
        success: function(results){},
        error: function(){}
    });

While in core nodejs the readfile function expects a callback like the following:

fs.readFile('./Index.html', function read(err, data) {}*)

If someone managed to get this to work or has a better solution to avoid the pyramid of callbacks in mobile services, just let me know.

ghost
  • 141
  • 8
  • 1
    You need to convert the API to promises manually via the promise constructor or deferred objects (check the dupe for more info). If I may suggest - Bluebird is two orders of magnitude faster than Q (about as fast as callbacks), it also has much better stack traces. – Benjamin Gruenbaum May 11 '14 at 12:36
  • just in case anyone else hesitated about how to install Q or Bluebird to the Azure Mobile Service - you need to clone the git repository (you have one by default, check settings), npm install Q -save, and then git push. – joeriks Jul 23 '14 at 11:59

0 Answers0