Comments (11)
This makes sense. Just to make sure, neither the MessageChannel
nor setTimeout
implementations are sufficient for your purposes? I would imagine the former is both available and sufficiently fast.
In any case, there is actually already a Q.nextTick
, but we'd need to change all the internal usages to reference exports.nextTick
instead of just nextTick
if we wanted to make setting it useful.
from q.
setTimeout()
is not available as a global in the mozilla addon environment.
serverSideRequire("event-queue")
will return a module I am providing BUT the addon sdk loader will not allow me to load the module without finding it declared in a static analysis pass (looking for require('<id>')
).
If I can set exports.nextTick
externally I can bypass all the current detection logic.
from q.
A settable nextTick
makes sense to me. I'm just wishing there was a way to make it work out of the box. Let me know if you think of anything.
I'll wait for @kriskowal to weigh in before committing anything though, since I don't understand all the security guarantees Q provides enough to know whether a settable nextTick
would break them.
from q.
Unfortunately there is no clean way to detect the addon sdk environment. Since setTimeout()
nor checking for serverSideRequire("timers").setTimeout
(due to not finding require('timers')
) will work I think the only solution is setting nextTick
externally.
The function could be cached on first use to avoid security implications if that helps.
from q.
I would prefer for the nextTick
underlying implementation to be injected somehow, rather than patched on post-instantiation. There are no securability issues if it’s injected, but there are security implication if we allow it to be replaced.
Bear in mind that this implementation of the Q interface does not make security guarantees. It just strives to behave identically to a hypothetical secure implementation like ref_send or makeQ. It is intended to pave the way, not be the way. That is, while it does make a lot of guarantees about the order of events (which are good for robustness in general), it does not guarantee that mutually suspicious programs could share the Q interface or share promise objects without fear of interference. To do so, it would have to freeze a lot more.
This is a tricky situation. @cadorn, does the MessageChannel implementation of nextTick
not work in the Addon SDK? I am thinking that the event-queue should be entirely subsumed by Q at this point.
from q.
@kriskowal typeof MessageChannel: undefined
injection is indeed the way to go and that will be available in future as we have more intelligent loaders but Q
is such a low-level module that it may be used without an injecting loader quite frequently (or even to implement the loader as in my case). I don't think the addon-sdk is alone when it comes to striving to provide a clean (minimal globals) module environment.
You can say; just patch Q
when you import it into your project; but that is not consistent with the current attempts to subsume the event-queue and provide an out-of-the-box experience.
The addon-sdk exposes require("timers").setTimeout()
but if used as serverSideRequire("timers").setTimeout
it will not allow access to the timers module as the static analysis fails. (I currently implement an event-queue
module and am adding require('event-queue');
to the top of q.js
).
To prevent replacing the nextTick
implementation it should be cached on first use. I think this is a fair workaround for the lack of injectability.
There are also cases when you want more control over nextTick
than Q
currently offers. In the addon-sdk the timers
implementation respects the lifecycle of the program and test runner. See: https://github.com/mozilla/addon-sdk/blob/master/packages/api-utils/lib/timer.js
I suppose if we decide against a one-time settable nextTick
I can look into teaching the addon-sdk loader the ability to allow loading of the event-queue
module (since it cannot find it by static analysis) by configuration from package.json
. This is a use-case not unique to this scenario but was hoping to hold off on for now.
from q.
@cadorn Does the addon runtime provide a reuqire.async(id, cb, eb)
hook?
from q.
@kriskowal No. They may if it becomes a commonjs spec though at which point it could be used instead of serverSideRequire
.
The problem is they want lean builds to generate addons that only contain what is needed. If using require.async(id, cb, eb)
we still have no way to determine what module is being referenced and would need a declaration in package.json
. This is a problem area I am working on in general (constraining require.async
for a module so we can gather possible IDs at build time in order to generate the dynamic load bundles). I have a working solution but am not happy with it. I think it will end up needing a pureJS load handler / dynamic linker that can be invoked at runtime or build time.
If we don't want to make changes to Q
to support the addon-sdk the consequence for addon-sdk developers is:
- Must use a non-enforcing loader instead of the stock one (I am about to test that by subclassing the stock loader) and
- Built add-on cannot be a lean build and must include all files.
This is fine for now but will not fly longer term.
from q.
@domenic
ie 10 supports MessageChannel, does nextTick via MessageChannel works under IE10 ?
from q.
@Yaffle Yes it does, although of course IE10 has native msSetImmediate
. See also YuzuJS/setImmediate@9be3252.
from q.
IE10 implemented setImmediate? Neato. Let’s use it.
from q.
Related Issues (20)
- unhandledRejection does not provide promise.stack HOT 1
- Is it possible to use a native Promise object with q ? HOT 1
- async function giving error HOT 1
- Q.allSettled returning unhandled rejection promises HOT 3
- Question : Global Error handling in Promise HOT 2
- Issues with Promise prototype. HOT 1
- Is Q a superset of a native Promise? HOT 4
- How do u like await? HOT 1
- Invalid token q.js?v=1588706333081:854 Invalid token HOT 1
- Google Analytics HOT 7
- Safari drops ticks for backgrounded tasks iOS 14 HOT 13
- Minified release?
- The q4 and after is so hard to understand HOT 1
- In v2, not v1, package.json uses deprecated form of license {} HOT 5
- Add warning and recommend native promises HOT 1
- Why return function ref ? HOT 6
- How can i convert an existing promise to a callback in Node.js ? HOT 1
- Need 'qs' version upadted to latest version to resolve Security Vulnerabilities HOT 2
- rasamaha
- Mark as deprecated on npm? HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from q.