[ 
https://issues.apache.org/jira/browse/TINKERPOP-1490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15682110#comment-15682110
 ] 

ASF GitHub Bot commented on TINKERPOP-1490:
-------------------------------------------

Github user davebshow commented on the issue:

    https://github.com/apache/tinkerpop/pull/478
  
    I put together a quick example of how this can be implemented in 
gremlin-python. Obviously the example is incomplete, but hopefully it can help 
move the discussion forward: 
https://github.com/apache/tinkerpop/commit/aa85a9b5278c55aa28014aa135c8498428295071
    
    These changes result in the following APIs depending on which Python future 
is returned by the driver, but the GLV doesn't care as long as it supports 
Python's common future API:
    
    - Tornado w/Python 2.7+ returning a `tornado.concurrent.Future`
    ```python
    @gen.coroutine
    def go():
        vertices = yield g.V().promise(lambda x: x.toList())
        assert len(vertices) == 6
        count = yield g.V().count().promise(lambda x: x.next())
        assert count == 6
    
     loop.run_sync(go)
    ```
    - Asyncio/Tornado with Python 3.5 async/await syntax returning 
`asyncio.Future` or `tornado.concurrent.Future`
    ```python
    async def go():
        vertices = await g.V().promise(lambda x: x.toList())
        assert len(vertices) == 6
        count = await g.V().count().promise(lambda x: x.next())
        assert count == 6
    
     loop.run_until_complete(go())
    ```
    - Driver with Python 2.7+ that returns `concurrent.futures.Futures` (or 
backport) 
    ```python
    def go():
        vertices = g.V().promise(lambda x: x.toList()).result()
        assert len(vertices) == 6
        count = g.V().count().promise(lambda x: x.next()).result()
        assert count == 6
    ```


> Provider a Future based Traversal.async(Function<Traversal,V>) terminal step
> ----------------------------------------------------------------------------
>
>                 Key: TINKERPOP-1490
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1490
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: language-variant, process
>    Affects Versions: 3.2.2
>            Reporter: Marko A. Rodriguez
>
> [~mbroecheler] had the idea of adding a {{Traversal.async()}} method. This is 
> important for not only avoiding thread locking on a query in Gremlin, but 
> also, it will allow single threaded language variants like Gremlin-JavaScript 
> to use callbacks for processing query results.
> {code}
> Future<List<String>> result = 
> g.V().out().values("name").async(Traversal::toList)
> {code}
> {code}
> Future<List<String>> result = g.V().out().name.async{it.toList()}
> {code}
> {code}
> g.V().out().values('name').async((err,names) => {
>   // I don't know JavaScript, but ...
>   return list(names);
> }) 
> {code}
> ...



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to