SHARE
TWEET

Untitled

a guest Jun 16th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. suspend fun query() {
  2.     driver.session().use { session ->
  3.  
  4.         val cursor: StatementResultCursor = session.readTransactionAsync {
  5.             it.runAsync("query ...", params)
  6.         }.await() // HERE WE DIE WITH OOM
  7.  
  8.         var record = cursor.nextAsync().await()
  9.  
  10.         while (record != null) {
  11.             val node = record.get("node")
  12.             mySuspendProcessingFunction(node)
  13.         }
  14.     }
  15. }
  16.      
  17. suspend fun query() {
  18.     session.readTransactionAsync { transaction ->
  19.         transaction.runAsync("query ...", params).thenCompose { cursor ->
  20.             cursor.forEachAsync { record ->
  21.                 runBlocking { // BUT I NEED TO DO RUN BLOCKING HERE :(
  22.                     val node = record.get("node")
  23.                     mySuspendProcessingFunction(node)
  24.                 }
  25.             }
  26.         }
  27.     }.thenCompose {
  28.         session.closeAsync()
  29.     }.await()
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top