Title: Support for Promises/A+? · Issue #180 · joeferner/node-java · GitHub
Open Graph Title: Support for Promises/A+? · Issue #180 · joeferner/node-java
X Title: Support for Promises/A+? · Issue #180 · joeferner/node-java
Description: Joe, would you consider adding support for Promises/A+ (i.e. merging a PR if I prepared one)? Currently node-java creates two javascript methods for every method of a class, an async version with the same name, and a sync version with th...
Open Graph Description: Joe, would you consider adding support for Promises/A+ (i.e. merging a PR if I prepared one)? Currently node-java creates two javascript methods for every method of a class, an async version with t...
X Description: Joe, would you consider adding support for Promises/A+ (i.e. merging a PR if I prepared one)? Currently node-java creates two javascript methods for every method of a class, an async version with t...
Opengraph URL: https://github.com/joeferner/node-java/issues/180
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support for Promises/A+?","articleBody":"Joe, would you consider adding support for [Promises/A+](https://promisesaplus.com/) (i.e. merging a PR if I prepared one)? Currently node-java creates two javascript methods for every method of a class, an async version with the same name, and a sync version with the 'Sync' suffix. We'd like to have a third variant, which is async but returning a promise. We have used both Q and Bluebird. I believe it is possible to implement a solution that would let users of node-java choose which promises library they would use, by simply adding to the node-java API the ability to pass in a 'promisify' function.\n\nSomething along the lines of:\n\n``` javascript\nvar java = require('java');\nvar asyncOptions = {\n promisify: require('q').nfbind // or require('bluebird').promisify\n suffix: 'Promise'\n};\njava.setAsyncOptions(asyncOptions);\njava.classpath.push(...);\n...\n```\n\nI use 'asyncOptions' instead of 'promisesOptions' since I imagine the possibility of disabling the generation of callback-style async methods, and only using promises.\n\nI've started inspecting the current node-java sources to figure out how to implement the change. There are some easy changes that can be made in lib/nodeJavaBridge.js, and perhaps that is the right place to promisify static methods, with code along these lines:\n\n``` javascript\n// copy static methods\nvar methods = clazz.getDeclaredMethodsSync();\nfor (i = 0; i \u003c methods.length; i++) {\n if (((methods[i].getModifiersSync() & MODIFIER_PUBLIC) === MODIFIER_PUBLIC)\n && ((methods[i].getModifiersSync() & MODIFIER_STATIC) === MODIFIER_STATIC)) {\n var methodName = methods[i].getNameSync();\n result[methodName + 'Sync'] = java.callStaticMethodSync.bind(java, name, methodName);\n result[methodName] = java.callStaticMethod.bind(java, name, methodName);\n result[methodName + asyncOptions.suffix ] = asyncOptions.promisify(result[methodName]); // Add just this one line\n }\n}\n```\n\nPromisifying instance methods is harder. It requires knowledge of v8 and nan that I don't yet have. I see that maybe the key changes would be localized to a few lines in javaObject.cpp, in the loop across instance methods around lines 45 to 56. I can probably figure it out with more study of the documentation for v8 and nan, but I wonder if you might be able to help me out with that part?\n","author":{"url":"https://github.com/jimlloyd","@type":"Person","name":"jimlloyd"},"datePublished":"2015-01-05T16:49:36Z","url":"https://github.com/joeferner/node-java/issues/180"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4cd1ae40-e6c6-8ae2-2ce0-551d2c65ef45 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9252:1007B2:90D17:CBCEF:6AFD4A74 |
| html-safe-nonce | 8d5936438110abc0d9d534febfc4cbdf3cdcc1db8cf4ce67728da275c018962e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjUyOjEwMDdCMjo5MEQxNzpDQkNFRjo2QUZENEE3NCIsInZpc2l0b3JfaWQiOiIxNjkzMjE5MTY2NjQ4ODc5NzMyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 455f63b369b9c95d63ca8a26bf1de54db07f1bf42c7ea29ee814804d4e029cb2 |
| hovercard-subject-tag | issue:53416541 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/joeferner/node-java/180/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7486546acdd4104759fedebaa6fd2d692e388fba9db0ff36f1c8f8c3b3309671/joeferner/node-java/issues/180 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7486546acdd4104759fedebaa6fd2d692e388fba9db0ff36f1c8f8c3b3309671/joeferner/node-java/issues/180 |
| og:image:alt | Joe, would you consider adding support for Promises/A+ (i.e. merging a PR if I prepared one)? Currently node-java creates two javascript methods for every method of a class, an async version with t... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jimlloyd |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| turbo-cache-control | no-preview |
| go-import | github.com/joeferner/node-java git https://github.com/joeferner/node-java.git |
| octolytics-dimension-user_id | 808857 |
| octolytics-dimension-user_login | joeferner |
| octolytics-dimension-repository_id | 3228734 |
| octolytics-dimension-repository_nwo | joeferner/node-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3228734 |
| octolytics-dimension-repository_network_root_nwo | joeferner/node-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width