Skip to content

Streams API is semi-broken #962

@arturaz

Description

@arturaz

I am working now on implementing otel4s integration for redis4cats and it seems impossible to do for streaming, because otel4s needs to have F[_]: MonadCancelThrow, but it does not exist for fs2.Stream and according to Fabio (SystemFw), he "strongly doubts it" that it's possible to add.

I suggest changing the APIs to this:

/**
  * @tparam F the IO type
  * @tparam S the stream type, like `fs2.Stream[IO, *]`
  */
trait PublishCommands[F[_], S[_[_], _], K, V] extends PubSubStats[F, K] {
  def publish(channel: RedisChannel[K], value: V): F[Unit]
  def publish(channel: RedisChannel[K]): S[F, V] => S[F, Unit]
}

/**
  * @tparam F the IO type
  * @tparam S the stream type, like `fs2.Stream[IO, *]`
  */
trait SubscribeCommands[F[_], S[_[_], _], K, V] {
  def subscribe(channel: RedisChannel[K]): S[F, V]
  def unsubscribe(channel: RedisChannel[K]): F[Unit]
  def psubscribe(channel: RedisPattern[K]): S[F, RedisPatternEvent[K, V]]
  def punsubscribe(channel: RedisPattern[K]): F[Unit]
}

trait PubSubCommands[F[_], S[_[_], _], K, V] extends PublishCommands[F, S, K, V] with SubscribeCommands[F, S, K, V]

This clearly shows which operations are one-shot, and which ones are streaming, instead of, for example, unsubscribe returning a stream with one element.

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