If you were to go down this road, it seems like you may as well just
go back to the EC-is-a-property-of-Future situation, which is
basically "the EC is not customizable"
Here's some code for that btw:
https://github.com/havocp/scala/commit/d6929a9125cbaad5b30f1892fc328e3916ab144b
I mean, why have an implicit EC if it has to be of the particular type
"per-request Play EC" anyway, you're really pretty much saying it has
to have a specific value, not just a specific type? In a given spot
there's only going to be one instance of "per-request Play EC".
It could make sense for Play to set this kind of policy since Play is
defining so much stuff for people already. In the above commit
FutureWithExecutionContext has a conversion back to Future which
allows people to override the EC if they really want to.
"futureWithEC.future.onComplete(callback)(myEC)"
I guess in theory people could make their own subtypes of "per-request
Play EC" that might do something like decorate the request EC with
debug tracing. Binding the EC to the future does restrict that kind of
customization. But you could allow it to be customized elsewhere, for
example maybe allow setting an EC factory on the Application instance.
For a per-request EC in Play, perhaps there's another strategy: try to
be sure the EC you really want is always imported... maybe put
"implicit def requestExecutionContext" in some typically-imported
package, and/or make some always-used APIs require your EC subclass to
be available implicitly... the idea would be that the correct EC is
already imported, so if someone accidentally imports another one,
there would be an ambiguity error. The only way to use a custom EC
would be to explicitly get rid of the Play per-request EC with "import
playEC => _"
Future[T, EC] seems like one of those cases (which I've often
encountered) where it might be nice conceptually to type-parameterize
something but it will create a problem because people will have to
write out or otherwise "deal with" that type parameter ....
Since you can never specify only some of the type parameters for a
class or method, if any of them are ambiguous or you for any reason
need to specify any of them, you always have to specify all of them.
So it's hard to have type parameters that are interesting in distinct
situations. Some code might want to specify T and some might want to
specify EC but all code will have to deal with both. I don't know,
I've found that I have to sort of pick which parameterization is most
useful for a given class or method and omit other potential
genericizations for sanity.
Just some offhand thoughts.
I might pursue the "try hard to be sure the Play per-request EC is
always imported so there's ambiguity if another one also is" idea
first just because it would be so much simpler (if it works) and would
not introduce a bunch of new API or API changes.
Both FutureWithExecutionContext and Future[T, EC] effectively fragment
Future into multiple incompatible kinds of Future, which for sure
increases complexity for app developers.
Havoc