[ https://issues.apache.org/jira/browse/TINKERPOP-1490?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15554888#comment-15554888 ]
Marko A. Rodriguez commented on TINKERPOP-1490: ----------------------------------------------- There are numerous "action/terminal"-methods off of {{Traversal}}. * {{next()}} * {{hasNext()}} * {{nextTraverser()}} * {{toList()}} * {{toSet()}} * {{iterate()}} * {{explain()}} * ... If we want asyncrhonous support for all terminal methods, then I think we shouldn't go down the route of {{nextAsync()}}, {{toListAsync()}}, etc. That is a bit dirty. Instead, I think we should have one method --- call it what we want --- that is basically a "future" that takes a {{Function<Traversal,V>}}. Thus, we can do: {code} g.V().out().future(Traversal::toList) g.V().out().future(Traversal::next) ... {code} In Java, its called a {{Future}}. Moreover, you can do {{CompletableFutures}} (https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html). Thus, I think we kill many birds with one stone here. We get "async" and "callback" support using one (and only one) method. Lets call it {{Traversal.future()}} given the status of the term "async." Thus, I propose that we add: {code} Future<T> Traversal.future(Function<Traversal,T>) {code} Lets get more specific and allow both "async" and "callback" via https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/FutureTask.html. {code} OurFuture<T> Traversal.future(Function<Traversal,T>) void OurFuture.then(Consume<T>) {code} ...where {{OurFuture}} will be a custom class based off of {{FutureTask}}. In sum total, you would then be able to do two things: {code} OurFuture<List<String>> result = g.V().out().values("name").future(Traversal::List) // some other stuff in parallel List<String> list = result.get() {code} ...and {code} g.V().out().values("name").future(Traversal::List).then(names -> System.out.println("Here are the names of everyone: " + names)) // some other stuff in parallel {code} Both async and callback support across all terminal {{Traversal}} methods. *** NOTE: I'm not married to {{future}} and {{then}} method names...so whateves. > 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)