Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement