Skip to content

[Idea] pause/resume/stop Stream and remove stopConsumption #941

@guizmaii

Description

@guizmaii

We had some discussion yesterday on Discord about removing stopConsumption
See:

Found a new idea this morning while taking my shower 😄
I think we could "generalize" the "interruptor" idea.
We could return a "control" interface that'd have 3 methods:

  • pause: would pause the stream
  • resume: would resume the paused stream
  • stop: would stop the stream and the subscription
// pseudo-code just to give show the idea
(
  val (control, stream0) = 
    Consumer
      .plainStream(Sub.topic("topic-a"), ...)
      .mapZIO(processRecord0(_))
      .runDrain

  control.pause() // pauses stream0
  control.resume() // resume stream0
  control.stop() // stop/finalize stream0
).provide(ZLayer.scoped(Consumer.make(settings)))

The "Control" interface would be something like:

trait Control {
  def pause: IO[AlreadyStopped, Boolean] // Boolean as we probably want to give a feedback to the user
  def resume: IO[AlreadyStopped, Boolean] 
  def stop: UIO[AlreadyStopped, Boolean]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions