On 4/22/2014 5:55 AM, Gijs Kruitbosch wrote:
On 22/04/2014 05:24, Joshua Cranmer 🐧 wrote:
For more specific explanation then:
I have a (non-negotiably) JS-implemented XPCOM service called the Folder
Lookup Service. I want to add an API to it called getOrCreateFolder that
returns a Promise<nsIMsgFolder>. I have non-negotiable C++ code that
wants to call this method, and do something when the promise is resolved
or rejected.

Dumb question time: why not provide an XPIDL'd alternative JS wrapper method (getOrCreateFolderForNativeConsumers or whatever) that takes two nsIRunnables or equivalent XPIDL'd C++ callback wrappers, and wrapping the getOrCreateFolder method with

.then((x) => successRunnable.run(x), (x) => failRunnable.run(x));

That's certainly possible, but, as my reviewer commented, if we want to start using promises a lot more in the API, it makes more sense to try to find a better solution now rather than proliferate ad-hoc solutions all over the place (the current state of the art is to stuff the thing being processed into a URL and use an nsIUrlListener, which doesn't work quite so well if the object isn't really a URL in the first place).

--
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

Reply via email to