sidorares/node-x11

return promises or thunks everywhere?

Opened this issue · 4 comments

Since generators are enabled by default in iojs and easily accessible behind flag in 0.12 it might be good to allow to yield values imagine we can have

var co   = require('co');
var x11 = require('x11');
co(function*() {
   var X = yield x11.createClient();
   var root = X.display.screen[0].root;
   var XSS = display.client.require('screen-saver');
   console.log( 'idle time: %s ', (yield XSS.QueryInfo(root)).idle );
});

instead of

var x11 = require('x11');
x11.createClient(function(err, display) {
    var X = display.client;
    X.require('screen-saver', function(err, SS) {
        if (err) throw err;
        SS.QueryInfo(display.screen[0].root, function(err, info) {
           if (err) throw err; 
           console.log('Idle time', info.idle);
        });
    });
    X.on('error', console.error);
});

not sure if it's easy to make co throw correct exception with proper stack trace when there is error from request where non-error response is not sent normally ( see #85 )

TBH I'm not familiar with promises at all :(. In case they were implemented, would the current API still be supported?

Yes, current api would still be supported as we don't return anything from async function

Since we can promisify any function having a callback, I'm 👎 this. Should be easy to create an x11-promise and keep this module as small as possible... ❇️

I'm -1 here as well but probably +1 for promise ( or dual promise + callback ) in higher level api. I already started adding promises to https://github.com/sidorares/ntk so you can do let children = await window.queryTree()