Last active
April 11, 2016 11:59
-
-
Save cb372/dd142d850c2962927d8b0436fe5773da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> def foo(a: Int): Future[Int] = memoize { Future { println("Computing..."); a + 1 } } | |
foo: (a: Int)scala.concurrent.Future[Int] | |
scala> foo(123) | |
res0: scala.concurrent.Future[Int] = List() // <-- WTF | |
scala> Computing... | |
scala> foo(123) | |
res1: scala.concurrent.Future[Int] = List() // <-- WTF | |
scala> res1 | |
res2: scala.concurrent.Future[Int] = Success(124) // <-- oh ok never mind (?) | |
scala> |
This is pretty interesting. I think I may have traced it down to the default implementation of Future
, which is DefaultPromise
that extends AbstractPromise.java
.
When one of those is initialised, the very first thing that happens is the internal state gets set to Nil
using updateState
. I think this is a very small window, and I can't reproduce what you've shown, but I'm fairly certain that is the List()
that you're seeing in res1 and res11.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I could also reproduce this more simply:
The problem went away with a fresh REPL.