Skip to content

Commit

Permalink
added mentions of loom addoon to the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rssh committed Sep 30, 2023
1 parent 8130018 commit af03404
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
16 changes: 12 additions & 4 deletions docs/BasicUsage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ Dependency
Sbt Example
-----------

The current prerelease is |0.9.18| for using with Scala |3.3.0|_.
The current prerelease is |0.9.19| for using with Scala |3.3.1|_.

.. code-block:: scala
libraryDependencies += "com.github.rssh" %% "dotty-cps-async" % "0.9.18"
libraryDependencies += "com.github.rssh" %% "dotty-cps-async" % "0.9.19"
JavaScript and Native targets are also supported.

.. code-block:: scala
libraryDependencies += "com.github.rssh" %%% "dotty-cps-async" % "0.9.18"
libraryDependencies += "com.github.rssh" %%% "dotty-cps-async" % "0.9.19"
**Note**: :red:`%%%` automatically determines whether we are in a Scala/JVM or a Scala.js or a Scala.Native project (see |Scala.js Cross-Building|_).

Expand All @@ -24,7 +24,15 @@ For using direct context encoding you also need to add compiler-plugin:
.. code-block:: scala
autoCompilerPlugins := true
addCompilerPlugin("com.github.rssh" %% "dotty-cps-async-compiler-plugin" % "0.9.18")
addCompilerPlugin("com.github.rssh" %% "dotty-cps-async-compiler-plugin" % "0.9.19")
If you use JDK-21 you can find helpful loom-based support for transforming arguments of high-order functions.
To enable one, add `dotty-cps-async-loom` module to the dependencies:

.. code-block:: scala
libraryDependencies += "com.github.rssh" %% "dotty-cps-async-loom" % "0.9.19"
Basic Usage
Expand Down
13 changes: 8 additions & 5 deletions docs/HighOrderFunctions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ Loom-based runtime await.

JDK-19 includes a set of interfaces (project Loom) that allows execution of code in virtual threads,
where runtime blocking wait is not blocking from OS view: real thread can execute tasks from other virtual threads during the wait.
In this case, we don't need to substitute a high-order function but change instead the function argument to the original form,
if our monad implements the `CpsRuntimeAwait <https://github.com/rssh/dotty-cps-async/blob/master/shared/src/main/scala/cps/CpsRuntimeAwait.scala>`_ typeclass.

This experimental feature should be enabled by declaring the implicit value of cps.macros.flags.UsingLoomAwait

In this case, we don't need to substitute a high-order function but change instead the function argument to the original form.
Target monad should implement one of the
`CpsRuntimeAwait` or
`CpsRuntimeAwaitProvider` typeclasses
(see
`sources <https://github.com/rssh/dotty-cps-async/blob/master/shared/src/main/scala/cps/CpsRuntimeAwait.scala>`_ )

For enabling this future, add `dotty-cps-async-loom` artifact to the dependencies of your project.


How to provide shifted functions.
Expand Down
8 changes: 8 additions & 0 deletions docs/Integrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Add dependency |cps-async-connect-cats-effect|_ to your ``build.sbt`` to integra
libraryDependencies += "org.typelevel" %% "cats-effect" % catsEffectVersion
libraryDependencies += "com.github.rssh" %%% "cps-async-connect-cats-effect" % cpsAsyncConnectVersion
For loom-based invocation of HO arguments on JDK-21+ also add `cps-async-connect-cats-effect-loom` artifact.

.. code-block:: scala
libraryDependencies += "com.github.rssh" %%% "cps-async-connect-cats-effect-loom" % cpsAsyncConnectVersion
|Cats Effect|_ GitHub : |typelevel/cats-effect|_, Maven : |org.typelevel»cats-effect|_.

**Note**: Typelevel's project |cats-effect-cps|_ also provides async/await syntax support for |Cats Effect|_.
Expand Down
25 changes: 7 additions & 18 deletions shared/src/main/scala/cps/CpsRuntimeAwait.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package cps

import scala.util._

//
// map: A=>B
// map_async: A=>F[B] ???
// f': A=>F[B], f'': A=>runtime.await(F[B])

/**
* When this typeclass is implemented for a monad F,
Expand All @@ -14,29 +8,24 @@ import scala.util._
**/
trait CpsRuntimeAwait[F[_]] {

/*
def async[A,C <: CpsTryMonadContext[F]](f: C=>A)(m: CpsAsyncEffectMonad[F], ctx:C):F[A] = {
m.flatDelay(runAsync(f)(m,ctx))
}
def runAsync[A,C <: CpsTryMonadContext[F]](f: C=>A)(m: CpsAsyncEffectMonad[F], ctx:C):F[A]
*/

def await[A](fa: F[A])(ctx: CpsTryMonadContext[F]): A


}

/**
* Indirect constructor for CpsRuntimeAwait[F] instance, which can be used in situation where
* runtime await instance can be build only inside of monad. (Example - cats.effect.IO)
*
* When this typeclass is implemented for a monad F, we also can process arguments of high-order functions
* wihout requiring of shifted variants.
*/
trait CpsRuntimeAwaitProvider[F[_]] {

//def applySync[A](lambda: CpsRuntimeAwait[F] => A)(using ctx:CpsTryMonadContext[F]): F[A]

def withRuntimeAwait[A](lambda: CpsRuntimeAwait[F] => F[A])(using ctx:CpsTryMonadContext[F]): F[A]

}



/**
* Marker class which mean that CpsRuntimeAwait implemented in such way,
* that performance penalty in comparison with cps run is relative low
Expand Down

0 comments on commit af03404

Please sign in to comment.