Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make for-yields parallel #8

Open
wyozi opened this issue May 2, 2017 · 2 comments
Open

Make for-yields parallel #8

wyozi opened this issue May 2, 2017 · 2 comments

Comments

@wyozi
Copy link
Owner

wyozi commented May 2, 2017

For instance the futures at

prodOpt <- productsDAO.findById(prodId)
devLicense <- productConfigDAO.getValue(prodId, "devlicense")
recentNewLicenses <- plpDAO.findRecentNewLicenses(prodOpt.get, 15, devLicense)
recentPings <- pingsDAO.findRecentForProduct(prodOpt.get, 15, devLicense)
will be completed sequentially instead of in parallel.

(http://stackoverflow.com/a/19046133)

@wyozi
Copy link
Owner Author

wyozi commented May 2, 2017

One solution would be changing

for {
  x <- fut1()
  y <- fut2()
  z <- fut3()
} yield (x, y, z)

to

(
  fut1() zip
  fut2() zip
  fut3()
) map {
  case (x, y, z) => (x, y, z)
}

@wyozi wyozi added the bug label May 2, 2017
@wyozi
Copy link
Owner Author

wyozi commented Jun 8, 2017

Also possible to define utility functions, i.e.

def par_tuple[E1, E2](e1: =>E1, e2: =>E2): Future[(E1, E2)] = {
  val f = future { e1 }
  val g = future { e2 }
  val h: Future[(E1, E2)] = for {
    x <- f
    y <- g
  } yield (x, y)
  h
}

(https://stackoverflow.com/questions/12923429/easy-parallel-evaluation-of-tuples-in-scala)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant