-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackage.scala
More file actions
41 lines (33 loc) · 1.68 KB
/
Copy pathpackage.scala
File metadata and controls
41 lines (33 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package io.nats.client
import cats.effect.Sync
import com.evolution.natseffect.jetstream.impl.JKeyValue
package object impl {
/** We defer to the NatsJetStreamPullSubscription implementation for the per-pull reply subject, not to mirror its internal pull counter.
*/
implicit class JNatsPullSubscriptionImplOps(a: JetStreamSubscription) {
/** Like `pull(PullRequestOptions)` (same `raiseStatusWarnings`, no observer), but returns the reply subject the pull request was
* published with - the subscription's wildcard inbox with `*` replaced by the internal pull counter. The server addresses everything
* belonging to the pull, statuses included, to this subject.
*/
def pullReturningSubject[F[_]](options: PullRequestOptions)(implicit F: Sync[F]): F[String] = F.delay {
a match {
case impl: NatsJetStreamPullSubscription => impl._pull(options, true, null)
case _ => throw new IllegalArgumentException("Subscription is not a NatsJetStreamPullSubscription")
}
}
}
/** We defer to NatsKeyValue implementation for stream and subject values calculation, not to reimplement the internal logic
*/
implicit class JNatsKeyValueImplOps(a: JKeyValue) {
private def visitImpl[F[_], R](visitor: NatsKeyValue => R)(implicit F: Sync[F]): F[R] = F.delay {
a match {
case impl: NatsKeyValue => visitor(impl)
case _ => throw new IllegalArgumentException(s"KeyValue is not a NatsKeyValue")
}
}
def getStreamName[F[_]](implicit F: Sync[F]): F[String] =
visitImpl(_.getStreamName)
def readSubject[F[_]](key: String)(implicit F: Sync[F]): F[String] =
visitImpl(_.readSubject(key))
}
}