scala - Future not working in Slick 3.1.x -


this function in slick prints "before future", doesn't print within future.map; seems future never executed, ideas problem?

note: i'm running slick standalone, not within play

   def readmany = {       val db = database.forurl("jdbc:mysql://localhost:3306/dddd",            driver="com.mysql.jdbc.driver", user="root", password="xxx")       val query = tablequery[tabledb]       val action = query.sortby(_.name).result       val future = db.run(action.astry)       println("before future")       future.map{          case success(s) => {           s.map {             row => somerow ( row.col1, row.col2 )           }           println("s:" + s)         }         case failure(e) => throw new exception ("failure in readmany: " + e.getmessage)         case _ => println("???")       }    } 

first of case _ => println("???") redundant, guess added debug statement. somerow never returned, readmany of type future[unit].

going issue, if running small code snippet, may want wait future complete (remember blocking on future in "real-world" application discouraged):

import scala.concurrent.duration._ import scala.concurrent.await  object foo extends app {   def readmany: future[unit] = ???   await.ready(readmany, 10 seconds) } 

calling await.ready waits until future becomes completed, not retrieve result. in same way, calling method not throw exception if future failed.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -