gopher.impl.DuppedInput.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scala-gopher_3.0.0-RC2 Show documentation
Show all versions of scala-gopher_3.0.0-RC2 Show documentation
scala-gopher: asynchronous implementation of CSP ( go-like channels/selectors ) in scala
The newest version!
package gopher
import cps._
import scala.annotation._
import scala.concurrent._
import scala.concurrent.duration._
import scala.util._
import java.util.concurrent.ConcurrentLinkedQueue
import java.util.concurrent.atomic.AtomicInteger
class DuppedInput[F[_],A](origin:ReadChannel[F,A], bufSize: Int=1)(using api:Gopher[F])
{
def pair = (sink1, sink2)
val sink1 = makeChannel[A](bufSize,false)
val sink2 = makeChannel[A](bufSize,false)
given CpsSchedulingMonad[F] = api.asyncMonad
val runner = SelectLoop[F](api).onReadAsync(origin){a => async{
val f1 = sink1.write(a)
val f2 = sink2.write(a)
true
}}.onRead(origin.done){ _ =>
sink1.close()
sink2.close()
false
}.runAsync()
api.asyncMonad.spawn(runner)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy