Let we have a simple system:
Interface MyAPI {
def iterator(): Iterator
}
With typical usage:
myAPI.iterator().take(10)
Let we have a simple system:
Interface MyAPI {
def iterator(): Iterator
}
With typical usage:
myAPI.iterator().take(10)
| package cps.examples | |
| import scala.concurrent.Await | |
| import scala.concurrent.ExecutionContext.Implicits.global | |
| import scala.concurrent.duration.Duration | |
| import scala.util.{Failure, Success} | |
| import cps.* // async | |
| import cps.monads.{*, given} // toFutureConversion | |
| import java.util.concurrent.CompletableFuture |
| async[FutureWithDeadline] { | |
| summon[DeadlineContext].setTimeout(100.millis) | |
| await(FutureSleep(1000.millis)) | |
| x = 1 | |
| } |
| val stream = asyncStream[Stream[Throwable,Int]] { out => | |
| for(i <- 1 to N) { | |
| out.emit(i) | |
| } | |
| } |
| // in src/main/scala/x | |
| package x | |
| // should pass compile | |
| case class TestMappingTemplate() derives ShowName { | |
| //... | |
| } | |
| // should fail on compile |
| val program = asyncRIO[TLogging] { | |
| val ctr = await(Ref.make(0)) | |
| while { | |
| val v = await(ctr.get) | |
| await(TLog.logMsg(v.toString)) | |
| if v % 3 == 0 then | |
| await(TLog.logMsg("fizz")) | |
| if v % 5 == 0 then | |
| await(TLog.logMsg("buzz")) | |
| await(ctr.update(_ + 1)) |
| package X | |
| import scala.util.Random | |
| object ScalaDaysRaffle | |
| { | |
| val participants = Seq( | |
| "Andrey Parhomenko" -> "http://github.com/team3", | |
| "Yurii Khomenko" -> "https://github.com/yurii-khomenko", | |
| "Victor Moskvych" -> "https://github.com/wouzar", |
| package x | |
| import scala.concurrent._ | |
| import scala.concurrent.duration._ | |
| import java.util.concurrent.{Future=>JFuture,_} | |
| object Implicits | |
| { |
| package scalax.concurrent | |
| import scala.concurrent._ | |
| import scala.concurrent.duration._ | |
| import scala.util._ | |
| class FutureWithErrorHandling[T]( | |
| origin: Future[T], | |
| errorHandler: Throwable => Unit = FutureWithErrorHandling.defaultHandler) | |
| (implicit ec: ExecutionContext) extends Future[T] |
| sourceGenerators in Compile += Def.task { | |
| val file = (sourceManaged in Compile).value / "bi" / "BuildInfo" | |
| IO.write(file, s"""package x; object BuildInfo { val millis =${System.currentTimeMillis}L }""") | |
| Seq(file) | |
| }.taskValue |