Skip to content

Instantly share code, notes, and snippets.

@joost-de-vries
Last active January 10, 2017 14:03
Show Gist options
  • Select an option

  • Save joost-de-vries/ec81d53d082a148d54ef8bc5ef599bd2 to your computer and use it in GitHub Desktop.

Select an option

Save joost-de-vries/ec81d53d082a148d54ef8bc5ef599bd2 to your computer and use it in GitHub Desktop.
Create a Reactive Streams Publisher from an actor
def scheduledPublisher(buffer: Int, initialDelay: FiniteDuration, interval: FiniteDuration)(
implicit actorSystem: ActorSystem): Publisher[Unit] = {
val actorSource = Source.actorRef[Unit](50, OverflowStrategy.fail)
val (actorRef, publisher) = actorSource.toMat(Sink.asPublisher(fanout = false))(Keep.both).run()
actorSystem.scheduler.schedule(initialDelay, interval, actorRef, ())
publisher
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment