atticoos / titanium-chromecast

:satellite: A Titanium Appcelerator GoogleCast SDK (chromecast) module
Other
26 stars 6 forks source link

Make KrollCallback promise-based #2

Open atticoos opened 9 years ago

atticoos commented 9 years ago

I hate callback structures. I'm already creating callback trees like

device.connect(function () {
  device.startApplication(function () {
    device.sendMessage('yo');
  }, function (error) {
    // start app error
  });
}, function (error) {
  // connect error
});

I would love to see:

device.connect().then(function () {
  return device.startApplication();
}).then(function () {
  return device.sendMessage('yo');
}).catch(function (error) {
  // error handler
});
AppWerft commented 8 years ago

It is easy: you write a wrapper with org.favo.promise to realize this.