I have a considerably big file(20-30 Mb) . I have a map where I have a key and the corresponding regex as value which I need to grep in the file to get the actual value of the key and store the new key,value in a new map . So here is my approach
contextmap //initial map which contains key and value in form of regex
contextstrings // final map supposed to have value after the grep
def fgrepFuture(e: (String,String)) = Future {
val re = new Regex(e._2)
Source.fromFile(f).getLines.foreach {
re findFirstMatchIn _ match {
case None => ("","")
case Some(x) =>(e._1,x.group(1))
}
}
}
val fg = Future.traverse(tmpmap)(fgrepFuture)
fg onComplete{
case tups => for(t <- tups) contextstrings += (t.toString.split(",").head -> t.toString.split(",").tail.head)
}
Problem here is that by the time future completes my rest of the code(based on asynchronous model of akka actors) moves ahead too far that I don't have the grepped value from file in quick time (which I want to be globally available).I need to get the values fast which I don't know why this approach is not giving me(since multiple future works in parallel),so please point out the flaw.Also if at all there is a better approach to get multiple value grepped from a considerably large file please suggest that as well.