Scala future recursion returning early -


I'm trying to use a recursive future call to get a tree with a certain depth Futures. Flatap quickly Beginning Returning

We have a graph database (the nodes in the tree) with the edges (parent's relationship) and institutions to regain the tree. For, we have two separate calls: getEdges and getEntitiesFromChildEdges. Return futures both.

Initial call, getEquipment, is needed to return a future. Since I eventually need to return the future, so I do not want to wait artificial.

Here is the code getEquipment is called the first time. GetTree (Root Entity: Seek [Unit], Parents: Seek [Unit], Depth: Int.): Future [SEQ [unit]] {GetEdges (Parents) .flatMap { Edges = & gt; GetEntitiesFromChildEdges (edges) .map {children = & gt; Children Fresh (child => ("lower", root entities) root entity} and {Log TheTree ("Dear", root entities) root entities (deep;); (depth; gt; 0) GetStream {Junk] {getRootEntities.flatMap {rootEntities = & gt; GetTree (rootEntities, Root Entity, 3) .flatMap {returnRootEntities => LogTheTree ("Final", root Entity) Json.toJson (rootEntities)}}

getEquipment is the first of these log results are said that the paste is completely created before the last returns Note logs with. < Dear Prior

  Dear Root Deaper One Final Root Ultimate One --- Depar Root Depar A Depar to Deper Three! Dear Root: DearPear One, Paste transversal is fourth-fourth, instead of gate-enter, getEntities reduce the call is not consistent with the question, but it helps to understand how a sequence has been passed to the tree transal.  

Finally, I know that I am unnecessarily in root entities I'm sorry, but the compiler complains when getTree.flatMap doesn ' returned RootEntities = & gt; Follow with . The real getEquipment: future is more complex, but it is for a different question. promise

to control this future based restructuring < Here's an example based on my comment to use / code>. I simplified your example so that code is cleaner, but still there are issues with the need to recycle the future . Take a look and hopefully you can pull it into your code:

  import concurrently. Future Import Scale. Insertion Promotional import concurrent Execution Contex Impulse ._ Import scale. Cancun Avate import concurrent period ._ case class person (id: long, name: string, children: option [list] long]] object recurssto app {vel each = map (1l -> person (1, "grandfather" , Some (list (3, "Kaka Joe", some (list (6, 2, 2) - (2, 2) - (2, "father", some (list (4,5)), 3l - Person (5, "Sis", none), 6L -> person (6, "cousin fried", none), 4L -> person (4, "me", none ), 5L ->, 7L -> Individuals (7, "Cousin Marie", none)) val f = getFamilMembers // Do not result in actual code val = await.result (f, 5 seconds) println (result) def getFamilMembers (): future [list [string]] = {var name : List [String] = List.empty val prom = Promise [List [String]] Def Richer (Eyes: List [Long]) {IDEd.Addedoption Match {// This Recording Exit Point Case is None & gt; Prom. Success (names.reverse) case some (id) = & gt; GetPerson (id) map {p = & gt; Names = p.name :: names val childIds = p.children.getOrElse (List.empty) recurse (IDs. Tail ++ childIds)}} recurse (list (1) prom.future} def getPerson (id: long): future [person] = {future suffering person =. (Id). Print Print ("Loaded:" + p.name) p}}}  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -