Since monadic composition is kind of ugly in Scala, I have created a library implementing coroutines based on delimited continuations as provided by the CPS transformation plugin for the Scala compiler. The library is available on git.benkard.de and GitHub.

Example use:

import monix.eval.Task
import monix.execution.Scheduler.Implicits.global
import monix.reactive.Observable

import eu.mulk.fibers.Fiber._

import scala.util.Success

val slowBackgroundTask = Task.delay(100)

def produceNumbers: Unit @fiber[Int] = {
  val Success(x) = await(slowBackgroundTask)
  emit(x)
  emit(x*2)
  emit(x*3)
}

val observable: Observable[Int] = run(produceNumbers)
observable.foreachL(println).runAsync  // => 100, 200, 300