Closed
Bug 838600
Opened 12 years ago
Closed 7 years ago
Extend Task.jsm
Categories
(Toolkit :: General, defect)
Toolkit
General
Tracking
()
RESOLVED
INVALID
People
(Reporter: Yoric, Unassigned)
Details
Task.jsm is great. Now, there are a few features that I would like to see added either to Task.jsm proper or to some external module TaskUtils.jsm.
In particular:
- error reporting;
- scheduling (i.e. yielding time back to the VM);
- waiting.
See bug 838577 for an example of how these features could be used.
Reporter | ||
Comment 1•11 years ago
|
||
Error reporting has been added a long time ago.
Comment 2•10 years ago
|
||
I wonder if something like this would be useful in Task[Utils].jsm. Mixing DOM events and promise/generators is a pain.
```
function awaitEvent(target, eventName, useCapture=false){
return new Promise((resolver)=>{
target.addEventListener(eventName, function listener(ev){
target.removeEventListener(eventName, listener, useCapture);
resolver(ev);
}, useCapture)
});
}
```
(optionally, could include a timeout to reject after a while)
Usage would be like:
```JS
const {
Task: {spawn, async, awaitEvent}
} = Components.utils.import('resource://gre/modules/Task.jsm', {});
fetchThingFrom(aBrowser).then(async(function* (thing){
let image = doc.createElement("img");
image.src = thing.src;
yield awaitEvent(image, "load");
doMoreFunThings();
}
```
Comment 3•10 years ago
|
||
(In reply to Marcos Caceres [:marcosc] from comment #2)
> I wonder if something like this would be useful in Task[Utils].jsm.
Looks quite similar to BrowserTestUtils.waitForEvent!
Not sure what a production API would look like - the advantage of treating this as test-only for now is that we're much more free to change the API since we know it will only be used in-tree. For example we just added the capture flag in bug 1170166. Anyways it wouldn't look as something to implement in TaskUtils.jsm, but more like something for a DOM utility module.
Reporter | ||
Comment 4•10 years ago
|
||
Perhaps in PromiseUtils.jsm?
Comment 5•10 years ago
|
||
Maybe DOMUtils.jsm or something.
Comment 6•7 years ago
|
||
Per bug 1515695, we're planning on removing Task.jsm at some point in the future.
David, is there anything in this bug that would still be wanted, but maybe located in something else?
Flags: needinfo?(dteller)
Reporter | ||
Comment 7•7 years ago
|
||
Well, if there are no utilities for waiting or error-reporting in any jsm, we probably want to add them.
Paolo would know this better than I do.
Flags: needinfo?(dteller) → needinfo?(paolo.mozmail)
Comment 8•7 years ago
|
||
We do already catch and report unhandled rejections caused by async functions in tests, and while there might be some use for a few of the utility functions described here, until now that hasn't come up in production code as much as in test code, so I'd say we could close this bug.
Status: NEW → RESOLVED
Closed: 7 years ago
Flags: needinfo?(paolo.mozmail)
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•