I’m glad to announce the first public release of dotty-cps-async: implementation of async/await transformation for Dotty, based on an optimized version of cps[continuation passing style] transformation, where continuation is ‘pushed’ to the monad. This release depends on the published version of the compiler and can-be downloaded from maven central.
Showcase:
- Full implementation of async/await: all language constructions are supported.
- Produce optimized code: the number of monad brackets is equal to the number of async operations, sequential parts run without additional overhead.
- Pluggable interface for continuation monads.
- Limited support for high-order functions:
```urls.map( httpClient.fetch() ).map(await())```` fetch all data from the list of URLs in parallel. - Miscellaneous additional futures, such as automatic coloring, custom value discard, and sip22 compatibility layer.
Files:
- Documentation: https://rssh.github.io/dotty-cps-async/
- Project on github: https://rssh.github.io/dotty-cps-async/
- SIP-22 compatible shim: https://github.com/rssh/shim--scala-async--dotty-cps-async
Some extra words about compatibility with scala2:
import cps.compact.sip22 provides a SIP22-like interface. All test cases from the original Scala-Async distribution successfully passed with a change of imports only and included in the regression suite.
It is also possible to compile sip22 async code without changing the source code with shim’s help: add to the dependencies ‘shim-scala-async-dotty-cps-async’ to scala3 dependencies instead scala-async for scala2.
Note that compatibility was not a primary goal during the development of dotty-cps-async. The generated code is quite different, so if you need a bug-to-bug compatible version of scala2 async, you should wait for the port of the original XAsync compiler plugin.