-
Notifications
You must be signed in to change notification settings - Fork 92
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
Scala 3 / Dotty plans? #232
Comments
It will find its way to Scala 3 in one form or another without requiring user code to change. We're actually experimenting at the moment with making this an actual compiler phase of Scalac, given how important the use case is. (Many other language that have |
@retronym , if it becomes a phase of Scala3 compiler, will it be possible for a method (not value) to return a T instead of Future[T] by using a top level await? Also will it be possible to use await inside a lambda? I really love how Kotlin coroutines allow you to do the above given that it captures the suspend effect using keyword. |
https://github.com/rssh/dotty-cps-async exists, not sure what its future is |
@mushtaq Moving into the compiler doesn't change the main restrictions on placement of awaits. Try/catch support (#89) is doable. Supporting use cases that await in lambdas is a bit harder. We could do some ad-hoc inlining of A more general solution requires a library of continuation-lifted versions of the combinators (#32) eg: def List_map_lifted[A, B](self: List[A])(f: A => Future[B]): Future[List[B] = async {
val result = ListBuilder[B]()
var rest = self
while (!rest.isEmpty) {
result += await(f(rest.head)
rest = rest.tail
}
result.result()
} And then a translation step to convert: def userCode = async {
List(1, 2 , 3).map(x => x * await(otherFuture))
} To: def userCode = async {
List_map_lifted(List(1, 2 , 3)(x => async { x * await(otherFuture) })
} Which would be valid for async. A slight variant of the them is to require the user to mark the spots where a rewrite is needed: def userCode = async {
List(1, 2 , 3).asyncably.map(x => x * await(otherFuture))
} Where The user could also opt in to running the map in parallel if they know that the lambda is pure. |
"I expect this will be ported to Scala 3", says Martin O: https://twitter.com/odersky/status/1276577949374955521 |
btw, https://github.com/rssh/shim--scala-async--dotty-cps-async now can be a workaround. (At least, all current test-cases are passed). |
I am new to Scala ... and find it is very difficult with async/await ... any idea if dsl.scala (https://github.com/ThoughtWorksInc/Dsl.scala) poses no restriction on where await can appear, or it is not that different? Thanks. |
@yangbao I'd suggest asking on https://users.scala-lang.org |
Now that Scala 3 is out, is there any decision on porting this lib? @retronym |
It's definitely something I want to work on, but I need to find a block of time to do the port. Hopefully will happen mid year. |
Good to know that @retronym! This will help a lot of projects to upgrade to Scala 3. |
A gentle reminder that someone is eagerly awaiting the Scala 3 port :) |
Btw, can I ask - why dotty-cps-async or shim--scala-async--dotty-cps-async (which is out of the box substitution) does not work for you? [not sure that this is the right place for this question, feel free to remove this or move to discussions] |
@rssh have not tried it yet. async/await is spread across our code base. If I am sure it works, but a bit hesitant to put in the releases. |
I just wanted to let you know I also ported Dsl.scala to Scala 3, and provided a Scala Async polyfill as well.
|
Just wanted to say that https://rssh.github.io/dotty-cps-async/index.html is working very well for me, so far. |
relevant new pre-SIP from 47 Degrees: https://contributors.scala-lang.org/t/pre-sip-suspended-functions-and-continuations/5801 |
and another new player in this space, from Prof. Odersky himself: https://github.com/lampepfl/async — includes slide deck from his talk at Scalar last week |
Just wondering if anybody had taken a look at how/if scala-async might work in Scala 3, given that the Scala 2 macro system as we know it will not survive? Is it still too soon to say?
It would be good to get some vibes about how confident we can be that the library might survive in some form into Scala 3, for deciding whether it's worth adopting it in an application.
The text was updated successfully, but these errors were encountered: