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


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to