[
https://issues.apache.org/jira/browse/TINKERPOP-1489?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15565361#comment-15565361
]
ASF GitHub Bot commented on TINKERPOP-1489:
-------------------------------------------
Github user jorgebay commented on the issue:
https://github.com/apache/tinkerpop/pull/450
I like the idea about returning promises. I think it could be a method
overload: user provides a function, use it as callback; otherwise, return a
promise. For runtimes that don't support promises, if no callback is provided,
throw an error. That way we can support all ES5+ runtimes (nashorn, nodejs,
browser js engines).
Example:
```javascript
// callback provided
g.V().hasLabel('person').toList((err, people) => {
people.forEach(console.log);
});
// callback not provided, a promise is returned
const peoplePromise = g.V().hasLabel('software').toList();
```
Promises in the Javascript landscape had the added benefit that can be used
along side generators (ES2015) and async/await (ES2017) in newer runtimes.
```javascript
// inside a generator
const people = yield peoplePromise;
// inside an async function
const people = await peoplePromise;
```
I think that if we provide both callback and promise method overloads, we
can avoid the need of a Promise polyfill.
About method generation:
I think the approach used by the Python GLV of generating methods is still
more user friendly than capture a function invocation. Using proxies is an
elegant solution, but compile time generated methods have several benefits over
[Javascript Proxy][1] approach:
- Compilers can optimize generated code.
- We can filter out Traversal/TraversalSource methods that we want to
handle differently.
- Node.js active LTS (v4) and most popular runtimes don't support it yet.
- The generated source is a defined API.
That way we could use the same approach from Python for all supported
languages.
[1]:
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy
> Provide a Javascript Gremlin Language Variant
> ---------------------------------------------
>
> Key: TINKERPOP-1489
> URL: https://issues.apache.org/jira/browse/TINKERPOP-1489
> Project: TinkerPop
> Issue Type: Improvement
> Components: language-variant
> Reporter: Jorge Bay
>
> It would be nice to have a Javascript Gremlin Language Variant that could
> work with any ES5 runtime, specially the ones that support
> [CommonJs|http://requirejs.org/docs/commonjs.html], like Node.js.
> Nashorn, the engine shipped with JDK 8+, does not implement CommonJs but
> provides [additional
> extensions|https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions]
> making modular JavaScript possible. Nashorn should be supported in order to
> run glv tests under the same infrastructure (JDK8).
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)