Getting data out of Cordova Plugin promises

I am using this plugin: https://github.com/jguix/Cordova-Flic


Flic.getKnownButtons(
function(buttons) {
console.log(‘Flic getKnownButtons succeeded’);
console.log('Flic known buttons: ’ + JSON.stringify(buttons));
},
function(message) {
console.log('Flic getKnownButtons failed: ’ + message);
});

How would one get the buttons variable out of the success function from the example above. I assume this is a type of promise as I can read it inside the function but if I try to save it to an external variable it comes out empty.

Hey @BradyG :blush:
I don’t want to make advertisement but i created a own Flic-Lib Plugin (which is maintained and works (the other one does not for me)). You can find it here: https://github.com/HansKrywaa/cordova-plugin-flic-lib

It also includes a Typescript Wrapper which should solve your question? :blush:

I lied a bit, I was using the flic plugin as an example but I am actually developing a plugin for the flic 2 which works similarly to the one I mentioned. It works I just can’t figure out how to get data out of the darn promises.

You can’t. That’s the point. At the bottom of all of it, you’re still really providing a callback, and only in the callback is the data available. Return the Promise, and hang a then off it in the ultimate caller.