On Fri, Dec 06, 2019 at 11:20:12AM +1300, Geoff Lankow wrote:
Hi all

I'm redesigning a bunch of Thunderbird things to be asynchronous. I'd like to use Promises but a lot of the time I'll be far from a JS context so that doesn't really seem like an option. The best alternative I've come up with is to create some sort of listener object and pass it to the async function:

interface nsIFooOperationListener : nsISupports {
 void onOperationComplete(
   in nsresult status,
   [optional] in string errorMessage
 );
};

...

void fooFunction(..., in nsIFooOperationListener listener);

This works fine but I wonder if there's a better way, or if there's some established prior art I can use/borrow rather than find out the pitfalls myself.

In general, if you're thinking about using an XPIDL interface for something, you're probably going down the wrong track. If you're only going to be dealing with C++, then you should generally use a pure C++ interface (probably just MozPromise in this case). If you're going to need to interact with JS at any point, you should probably just use dom::Promise. You can always use AutoJSAPI to get a JSContext, and create the Promise in the shared JSM global.
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to