Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-2167

Gremlin Javascript Traversal as async iterable

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Done
    • Affects Version/s: 3.4.0
    • Fix Version/s: 3.3.6, 3.4.1
    • Component/s: javascript
    • Labels:
      None
    • Environment:
      Node v10.15.0

      Description

      Traversals in Gremlin javascript are async iterators, as they implement a next() method that returns a Promise, which resolves to an object with value and done properties. It would be helpful if they were also async iterables - traversable via for await ... of loops.

      (async function() {
        for await (const continent of g.V().hasLabel('continent').values('desc')) {
          console.log(continent)
        }
      })()
      

      Expected output:

      > Africa
      Antarctica
      North America
      Asia
      Oceania
      Europe
      South America
      

      Current output: (Node v10.15.0)

      > (node:14698) UnhandledPromiseRejectionWarning: TypeError: g.V(...).hasLabel(...).values(...) is not a function or its return value is not async iterable
          at repl:1:78
          at repl:1:122
          at Script.runInThisContext (vm.js:96:20)
          at REPLServer.defaultEval (repl.js:332:29)
          at bound (domain.js:395:14)
          at REPLServer.runBound [as eval] (domain.js:408:12)
          at REPLServer.onLine (repl.js:639:10)
          at REPLServer.emit (events.js:187:15)
          at REPLServer.EventEmitter.emit (domain.js:441:20)
          at REPLServer.Interface._onLine (readline.js:290:10)
      (node:14698) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
      (node:14698) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
      

      This can be achieved by adding [Symbol.asyncIterator] to the Traversal class.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jorgebg Jorge Bay
                Reporter:
                joestrouth1 Joe Strouth
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - 24h
                  24h
                  Remaining:
                  Remaining Estimate - 24h
                  24h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified