0

Is it possible to create a Source to which I'm going to be able to push data "manually" (or I can do it somehow to a "regular" Source)?

Something like:

var source = Source.Empty<int>();
source.Push(10); //is something like this possible?

My use case would be creating a source to which I'm able to push data whenever my API endpoint is called.

Tomasz Madeyski
  • 10,742
  • 3
  • 50
  • 62
  • Possible duplicate of [How to create a Source that can receive elements later via a method call?](https://stackoverflow.com/questions/30964824/how-to-create-a-source-that-can-receive-elements-later-via-a-method-call) – Ramón J Romero y Vigil Aug 31 '18 at 11:56

1 Answers1

4

Yes, it's possible. Check out Source.Queue:

Source.Queue can be used for emitting elements to a stream from an actor (or from anything running outside the stream). The elements will be buffered until the stream can process them. You can Offer elements to the queue and they will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received.

Another option is Source.ActorRef:

Messages sent to the actor that is materialized by Source.ActorRef will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received.

Unlike Source.Queue, Source.ActorRef does not support backpressure.

Jeffrey Chung
  • 19,319
  • 8
  • 34
  • 54