Skip to content

Instantly share code, notes, and snippets.

View rssh's full-sized avatar

Ruslan Shevchenko rssh

View GitHub Profile

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
@rssh
rssh / FutureWitDeadline.scala
Created November 15, 2021 07:55
we can have awaits with timeout
async[FutureWithDeadline] {
summon[DeadlineContext].setTimeout(100.millis)
await(FutureSleep(1000.millis))
x = 1
}
@rssh
rssh / generator.scala
Created September 5, 2021 11:20
Generator usage in dotty-cps-async
val stream = asyncStream[Stream[Throwable,Int]] { out =>
for(i <- 1 to N) {
out.emit(i)
}
}
@rssh
rssh / Main.scala
Created April 22, 2021 04:08
dn-q: ShowLabel
// in src/main/scala/x
package x
// should pass compile
case class TestMappingTemplate() derives ShowName {
//...
}
// should fail on compile
@rssh
rssh / ziofizzbuzz.scala
Created April 13, 2021 17:49
example of using ZIO with dotty-cps-async
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))
@rssh
rssh / Winner determination script
Created April 11, 2018 20:31
Winner of SalaDays tickets Raffle
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",
@rssh
rssh / X.scala
Last active April 11, 2016 06:57
Full example to Future behaviour changed in dependency from execution context 'why scala is not my ideal language' presentation on #scalaua 2016
package x
import scala.concurrent._
import scala.concurrent.duration._
import java.util.concurrent.{Future=>JFuture,_}
object Implicits
{
@rssh
rssh / FutureWithErrorHandling.scala
Last active March 4, 2016 12:48
sketch for future with error handlign
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