-
Notifications
You must be signed in to change notification settings - Fork 7.3k
implement domain-like hooks (asynclistener) for userland #6011
Conversation
This would meet my requirements, as long as the async listener also fires for the timer functions and is invoked from Make(Domain)Callback. Also, I'm pretty sure that if you're going to expose a generic hook like this, it's going to need the ability to accept multiple listeners. If those are pieces you plan to add to this, 👍 from me. |
@othiym23 thanks for the feedback. that was along the lines of what I was attempting. exposing multiple listeners is easy. already have a patch for it, but removed it when I realized that users could easily wrap callbacks in callbacks in callbacks. and there's no guaranteed order of firing. also, do I only allow the same listener to be added once, or can they add multiple? it was getting complicated fast so it was dropped so I could get something solid posted. i'll happily add it back if there's a clear road of where it should go. |
I think the most sensible, intuitive way for this to work would be to run the listeners in the order that they were registered via It's hard to avoid some difficulty with ordering dependencies, though. It might be enough to offer two calls to add a listener -- I don't really have it clear in my head, but it seems like it could be possible to use that object you were talking about yesterday as a means for these wrappers to share their state, and maybe externalize whatever data might otherwise subject to dependencies. But down that road lies a whole bunch of other annoying complications and complexity. |
I just sent pull requests to CLS to use this API and to CLS-Glue to prollyfill this API.
@trevnorris did I implement the proposed API correctly in the polyfill? |
@othiym23 Also, once/if this lands in core and CLS becomes peer to Domains instead of domains being implemented on top of CLS, I recommend simplifying the CLS API and implementation to be just data storage. https://gist.github.com/creationix/d531157ad587a4af9f4e#file-multi-cls-js |
@creationix: I went ahead and split your proposed changes out into an entirely separate module, @trevnorris, what this means is that we now have a polyfill for versions of node < (whatever version of Node this lands in). I'll keep it up to date with your changes, and you can grab a copy of |
@othiym23 Thanks. Trying to have basics working by NodeConf.eu, but working around everything already in place has been a little painful. To be honest one problem is that I'm catching more asynchronous callbacks then expected. Which make the tests unpredictable. So I need to trace down where every one is occurring so they can be accounted for. |
if (domain) domain.exit(); | ||
|
||
if (domain) | ||
domain.exit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought domains were going to be implemented in terms of async listeners?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still in the middle of figuring that out. Domains are so tightly coupled
with the EventEmitter that it's been a little difficult.
Everything relevant is landed in master now, right? Reopen if there's still work to do here. Thanks for all the work on this, @othiym23, @jacobgroundwater, and especially @trevnorris. |
@trevnorris why are namespace.set('test', TEST_VALUE);
server = net.createServer();
server.on('connection', function OnServerConnection(socket) {
expect(namespace.get('test')).equal(TEST_VALUE, "state should be preserved"); // Still have state
socket.on("data", function OnServerSocketData(data) {
expect(namespace.get('test')).equal(TEST_VALUE, "state should still be preserved :("); // cls is lost |
@refack I'm not sure why you direct that question to me. |
Sorry ment to ping @trevnorris |
@refack If I understand the question, it's because internally we don't know whether you're creating a Pipe or a TCP connection until you call listen(). It's a total PITA. I have another PR open that does some work on this, but still under debate how it should be merged. |
Is it landed on any released version? |
@RobinQu Never landed. |
So, will node have this feature some day? |
@gobwas It partially exists as EDIT: It's in io.js, not node.js. |
Thank you, @trevnorris! Does this feature present in iojs docs? Any way, I am asking about async-listener functionality at the moment..? |
Oh, that died a horrible death. After 3 months of work I still couldn't figure out a few key edge cases. So instead I've been working on the set of hooks necessary to implement a feature like async-listener. This way others can experiment and publish their own modules. |
Hi @trevnorris , could you give us an update on the current status of this? What would be your suggestion to use these days if we want to active the same functionality? Thanks! cc @Peteyy |
@gergelyke Unfortunately there isn't an alternative. Will have to continue using domains for the time being. Though discussion about reimplementing this has started back up. Hopefully it will lead to something. |
thanks! |
What is wrong with the Domain solution? |
@naorye It's a complete hack that injects itself all over core code. By design it can't properly catch everything. There are edge cases it's missing. This is because it's injected at the JS API level, not at the native level where the asynchronous requests are actually made. |
What alternatives are now being discussed? |
@trevnorris Is there any other solutions based on native layer of this problem currently available? I am a Java coder, I think if this should be done on VM layer which make things easier and more efficient. |
@jiaqifeng In master there's a native API that can be used (see all functions that use |
Here's the current API planned for implementation: