I'm looking for akka.stream.scaladsl.Source
construction method that will allow me to simply emit next value from different place of code (e.g. watching on system events).
- I need somethig similar to
Promise
. Promise emits single value toFuture
. I need to emit multiple values toSource
. - like
monix.reactive.subjects.BehaviorSubject.onNext(_)
- I don't care about backpressure too much.
currently I've implemented this using monix & akka-streams (code below) but I expect that there should be akka-streams only sollution:
import akka.stream.scaladsl.{Flow, Sink, Source}
import monix.reactive.subjects.BehaviorSubject
import monix.execution.Scheduler.Implicits.global
val bs = BehaviorSubject("") //monix subject is sink and source at the same time
//this is how it is currently implemented
def createSource() = {
val s1 = Source.fromPublisher(bs.toReactivePublisher) //here we create source from subject
Flow.fromSinkAndSourceCoupled[String, String](Sink.ignore, s1)
}
//somewhere else in code... some event happened
//this is how it works in monix.
val res:Future[Ack] = bs.onNext("Event #1471 just happened!") //here we emit value