How to add elements to Source dynamically?
I have example code to generate an unbound source and working with it: object Main { def main(args : Array[String]): Unit = { implicit val system = ActorSystem("Sys") import system.dispatcher implicit val materializer = ActorFlowMaterializer() val source: Source[String] = Source(() => { Iterator.continually({ "message:" + ThreadLocalRandom.current().nextInt(10000)}) }) source.runForeach((item:String) => { println(item) }) .onComplete{ _ => system.shutdown() } } } I want to create class which implements: trait MySources { def addToSource(item: String) def getSource() : Source[String] } And I