# Announce: first public version of dotty-cps-async \[async/await transformer for dotty\]

**URL:** <https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494>\
**Category:** Scala 3 Release Projects\
**Created:** [September 4, 2020, 6:15am UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494 "2020-09-04T06:15:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rssh](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/rssh/32/745_2.png) [@rssh](https://contributors.scala-lang.org/u/rssh)\
**Post date:** [September 4, 2020, 6:15am UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494/1 "2020-09-04T06:15:59Z")

</div>

I’m glad to announce the first public release of dotty-cps-async. 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(_))` can be an idiomatic way to fetch all URLs from the list 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/](https://rssh.github.io/dotty-cps-async/)
- Project on Github: [https://github.com/rssh/dotty-cps-async](https://github.com/rssh/dotty-cps-async)
- SIP-22 compatible shim: [https://github.com/rssh/shim--scala-async--dotty-cps-async](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.

---

<div class="post-metadata">

**Author:** ![rssh](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/rssh/32/745_2.png) [@rssh](https://contributors.scala-lang.org/u/rssh)\
**Post date:** [July 23, 2021, 6:12am UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494/2 "2021-07-23T06:12:20Z")

</div>

0.9.0 is published:  
What was changed since 1-st public release, in the version, which is available for scala 3.0.1 final:

Main points behind bug fixing:

- Implemented async variants for most high-order functions from scala standard library; Now if you use await inside for loop or fold – usually, it just works.

- Simplified setting of shifted version of high-order functions: now developer can declare one inplace, instead creating an extra typeclass.

- Implemented support oft custom call-chain builders: I.e. the following expression  
`for( url <- urls if await(score(url)) > 0) yield await(fetch(url))`  
will traverse through `urls` only once, because we can merge filter and map in `WithFilter` call-chain builder.

- Implemented support of automatic coloring:  
I.e. we can write something like:

```auto
  async {
       val auth = db.retrieveAuth(url) 
       val data = fetchData(auth,url)
       if (isInteresting(data)) then
             db.increaseScoring(url)
}

```

the compiler will insert needed awaits automatically.

This works not only for plain Futures but also for effect monads, such as cats-effects IO, Monix, and ZIO. (see note about this: [notes/2021\_06\_27\_automatic-coloring-for-effects.md at master · rssh/notes · GitHub](https://github.com/rssh/notes/blob/master/2021_06_27_automatic-coloring-for-effects.md) )

- ScalaJS:  
– Implemented support for non-monadic objects in awaited statements (i.e., `js.Promise`) - now it is possible use `await(js.Promise)` inside async block.  
– Implemented `JSFuture`, which looks like ‘promise’ from the js side, but as typed monad on scala side.

It was tested in few internal projects and open-source libraries, depending from dotty-cps-async

---

<div class="post-metadata">

**Author:** ![Swoorup](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/swoorup/32/1935_2.png) [@Swoorup](https://contributors.scala-lang.org/u/Swoorup)\
**Post date:** [July 26, 2021, 3:49pm UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494/3 "2021-07-26T15:49:26Z")

</div>

So this is similar to something like F# Computation Expression?

---

<div class="post-metadata">

**Author:** ![rssh](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/rssh/32/745_2.png) [@rssh](https://contributors.scala-lang.org/u/rssh)\
**Post date:** [July 26, 2021, 7:08pm UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494/4 "2021-07-26T19:08:41Z")

</div>

- Yes: the main similarity - it’s a way to embed arbitrary ‘generic (monad + optional extras)’ computation into control flow.
- Differences ( ‘no’ smaller than ‘yes’).
  - Note, that F# has no HKT, so the meaning of ‘generic computation’ in F# and scala is quite different.
  - F# computation expression differs from base language, in dotty-cps-async internal and base language is literally the same.

---

<div class="post-metadata">

**Author:** ![amitport](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/amitport/32/1739_2.png) [@amitport](https://contributors.scala-lang.org/u/amitport)\
**Post date:** [July 27, 2021, 9:50am UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494/5 "2021-07-27T09:50:01Z")

</div>

This looks very interesting!

Please, is it possible to write a friendly basic usage page?  
[https://rssh.github.io/dotty-cps-async/BasicUsage.html#basic-usage](https://rssh.github.io/dotty-cps-async/BasicUsage.html#basic-usage)

The current one really assumes a lot of familiarity specific to scala’s async libraries and a research niche.

CpsAsyncMonad and the like are really not that common terminology for someone that is coming from python/javascript/c#. To be honest, even tough I’ve written parsers in scala and async-await AST transformations in other languages I really can’t follow this introduction (I find it easier to go over the code).

---

<div class="post-metadata">

**Author:** ![rssh](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/rssh/32/745_2.png) [@rssh](https://contributors.scala-lang.org/u/rssh)\
**Post date:** [July 28, 2021, 4:36am UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494/6 "2021-07-28T04:36:02Z")

</div>

Thanks. Will think what is possible to-do.

[btw, will be grateful for for the comments/patches in the ticket: [Improve introduction documentation · Issue #48 · rssh/dotty-cps-async · GitHub](https://github.com/rssh/dotty-cps-async/issues/48) ]

---

<div class="post-metadata">

**Author:** ![Swoorup](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/swoorup/32/1935_2.png) [@Swoorup](https://contributors.scala-lang.org/u/Swoorup)\
**Post date:** [July 28, 2021, 8:21am UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494/7 "2021-07-28T08:21:20Z")

</div>

The terminology gave me a reminder how noob I am. 😂 Thanks for that.

---

<div class="post-metadata">

**Author:** ![rssh](https://contributors.scala-lang.org/user_avatar/contributors.scala-lang.org/rssh/32/745_2.png) [@rssh](https://contributors.scala-lang.org/u/rssh)\
**Post date:** [August 21, 2023, 1:26pm UTC](https://contributors.scala-lang.org/t/announce-first-public-version-of-dotty-cps-async-async-await-transformer-for-dotty/4494/8 "2023-08-21T13:26:46Z")

</div>

0.9.18. bring a compiler plugin with support for direct context encoding, which can be a practical next intermediate step in the journey of asynchronous API development.

```auto
@experimental
class DToyLogger(ref: Ref[IO,Vector[String]]):

  def log(message: String)(using CpsDirect[IO]): Unit =
    await(ref.update(lines => lines :+ message))

  def all()(using CpsDirect[IO]): Vector[String] =
    await(ref.get)
    
@experimental    
object DToyLogger:    
  
  def make()(using CpsDirect[IO]): DToyLogger =
    val ref = await(Ref.of[IO,Vector[String]](Vector.empty))
    DToyLogger(ref)

```
