-
Notifications
You must be signed in to change notification settings - Fork 290
First rough draft of adding support for promises. #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Whoops, the Travis build failed for all node v0.8 and v0.11, but passes for all node 0.10. I only tested on my dev MacBook with node 0.10. I just tested with v0.11 and reproduced the error. Hopefully there is some NAN trick we can apply to the code to make it work on all three node versions. I'll start looking into that, but please let me know if there is an obvious fix. |
|
The last two commit seemingly fix the build problems for all 9 cases in our test matrix, but actually there is still an intermittent failure on node 0.10 (at, least, it's easy to reproduce on that version. I have not seen it in several attempts on node 0.11): @joeferner as you review the code, please look for causes of this ref/unref problem. I'll look deeper into it tomorrow. |
|
@joeferner I haven't made any progress on the ref/unref problem. It seems to be specific to node 0.10, as I have never seen it in many attempts with node 0.8 and 0.11, but it seems to happen at least half of the time with 0.10. Note I am testing with 0.8.28, 0.10.35, and 0.11.14. I'm going to set this aside and work on some other tasks until you've had a chance to take a look and provide some feedback. Thanks. |
|
I think that "ERROR" is unrelated. If you look at master and run the tests. You'll get the same error. It will appear in random locations based on what the garbage collector is doing at the time. |
src/javaObject.cpp
Outdated
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.
We may want to fail hard here. I'm pretty sure everything after this will not like it if result is not a function. In checkJavaException node-java assert(false) after printing the error. It would be nice to throw an exception but I'm not sure if that's allowed in the New method.
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.
Yes, this check was partly just my debug diagnostics. But if a user passes in an invalid promisify function, one that doesn't return a function, then we should catch the error here. I agree that assert(false) in acceptable in this case.
|
It's looking really good. Is there anything else left? Looks like you handle the two big cases, instance methods and static methods. |
|
Ok, I see now that the error could be unrelated. It's a little disturbing that it happens so frequently during the promises test with node 0.10, but since it happens elsewhere it probably is safe to ignore. |
|
I still haven't promisified the async methods of Java module: newInstance, callMethod, callStaticMethod. I plan to implement those soon so we can include them in the first release of this feature. |
…tead of 'suffix'.
Joe, I implemented an onJvmCreated callback so I could do the promisification from javascript instead of C++. Let me know if you have reservations about this approach.
|
@joeferner If you are ok with the above commits then all that remains is to update the README.md. Note, I changed asyncOptions.suffix -> asyncOptions.promiseSuffix as I anticipate we may want to allow changing the Sync suffix, and maybe add non-empty suffix for Async. Actually I have even more ambitious plans that I will propose to you later. Also, see the commit comment for the last commit. I added an onJvmCreated callback to javascript. Any concerns about that approach? |
|
@joeferner I've updated the README.md. But in the process I tested with Q, which is probably the most commonly used promises library, and was surprised to discover that it doesn't work. It's a bit unsettling. Given that 2 of 3 libraries tested work, it may be reasonable to release as is. The incompatibility is documented in the README.md. But it might be worth holding the release until we understand the problem better, or have tested with more promises libraries. FYI, the error is: The stack crawl looks like this: |
|
I hit 'Close and comment' by mistake, I meant to just submit the comment. |
|
This PR is superseded by PR #187. |
@joeferner: Hi Joe, I managed to get something working for Issue #180.
This only promisifies the instance methods of the imported java classes, but adding support for static methods and promisifying the Java module itself is probably trivial in comparison.
Please review the changes in java.cpp and javaObject.cpp carefully. This implementation was almost blind trial and error without really trying to understand v8 and NAN. In particular I haven't tried to study how to properly handle garbage collection so I may have made mistakes there.
TODO: