On 12/5/2019 6:33 PM, Gerald Squelart wrote:
On Friday, December 6, 2019 at 9:20:21 AM UTC+11, 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.
TIA,
GL
We have mozilla::MozPromise [0], similar to mozilla::dom::Promise but it
doesn't rely on JS at all.
It can be a bit tricky to use, the simplest way (to start) is probably to do
something like InvokeAsync(work thread, code to run that resolves or rejects the
promise)->Then(target thread, on-success follow-up, on-failure follow-up)
(e.g., [1]).
The problem with MozPromise is that it doesn't integrate well if you use
XPIDL interfaces, so you have this annoying issue that if you want to
use XPIDL integration, you have to use mozilla::dom::Promise, which is
annoying to use from C++. A third wrinkle, especially now that async
functions has landed in Rust, is if you want to try to use
std::future::Future in Rust, which isn't going to convert terribly well
to either form.
It may be worth spending some time building some wrappers to integrate
between all of our various async function frameworks...
--
Joshua Cranmer
Thunderbird and DXR developer
Source code archæologist
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform