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

stephen mallette edited comment on TINKERPOP-1490 at 10/8/16 11:54 AM:
-----------------------------------------------------------------------

{{future}} with an extension of {{FutureTask}} seems good to me, though i don't 
think we should ignore {{CompletableFuture}}. {{Traversal}} should have:

{code}
void promise(CompletableFuture future)  // perhaps we just start a thread to 
iterate the traversal (i.e no thread pool)
void promise(CompletableFuture future, ExecutorService executor)  // in this 
case we provide a thread pool to execute in
{code}

{{CompletableFuture}} provides a lot more flexibility for handling exceptions, 
starting async tasks in different executors, and clarifies situations with lots 
of callback chaining. It makes it trivial to do stuff like:

{code}
promiseOutNames = new CompletableFuture()
promiseInNames = new CompletableFuture().thenAccept(f -> transformResult(f))  
promiseBothNames = promiseInNames.thenCombine(promiseOutNames, (in,out) -> 
combineInOut(in, out)).
                                                               thenRunAsync(f 
-> notifySomethingOfBoth(f), gremlinServerExecutorService)
g.V(1).out().values("name").promise(promise1)
g.V(1).in().values("name").promise(promise2)
{code}

So the above would traverse in/out vertices in parallel across two separate 
threads, combine the results and then make an async call to notify some service 
about the combined results. 


was (Author: spmallette):
{{future}} with an extension of {{FutureTask}} seems good to me, though i don't 
think we should ignore {{CompletableFuture}}. {{Traversal}} should have:

{code}
void promise(CompletableFuture future)  // in this case, perhaps we just start 
a thread to iterate the traversal in gremlinServerExecutorService (i.e no 
thread pool)
void promise(CompletableFuture future, ExecutorService executor)  // in this 
case we provide a thread pool to execute in
{code}

{{CompletableFuture}} provides a lot more flexibility for handling exceptions, 
starting async tasks in different executors, and clarifies situations with lots 
of callback chaining. It makes it trivial to do stuff like:

{code}
promiseOutNames = new CompletableFuture()
promiseInNames = new CompletableFuture().thenAccept(f -> transformResult(f))  
promiseBothNames = promiseInNames.thenCombine(promiseOutNames, (in,out) -> 
combineInOut(in, out)).
                                                               thenRunAsync(f 
-> notifySomethingOfBoth(f), gremlinServerExecutorService)
g.V(1).out().values("name").promise(promise1)
g.V(1).in().values("name").promise(promise2)
{code}

So the above would traverse in/out vertices in parallel across two separate 
threads, combine the results and then make an async call to notify some service 
about the combined results. 

> 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