MCPcopy Create free account
hub / github.com/Effect-TS/effect / subscribe

Function subscribe

packages/effect/src/PubSub.ts:1077–1088  ·  view source on GitHub ↗
(self: PubSub<A>)

Source from the content-addressed store, hash-verified

1075 * @since 2.0.0
1076 */
1077export const subscribe = <A>(self: PubSub<A>): Effect.Effect<Subscription<A>, never, Scope.Scope> =>
1078 Effect.uninterruptible(
1079 Effect.contextWith((services) => {
1080 const localScope = Context.get(services, Scope.Scope)
1081 const scope = Scope.forkUnsafe(self.scope)
1082 const subscription = makeSubscriptionUnsafe(self.pubsub, self.subscribers, self.strategy)
1083 return Scope.addFinalizer(scope, unsubscribe(subscription)).pipe(
1084 Effect.andThen(Scope.addFinalizerExit(localScope, (exit) => Scope.close(scope, exit))),
1085 Effect.as(subscription)
1086 )
1087 })
1088 )
1089
1090const unsubscribe = <A>(self: Subscription<A>): Effect.Effect<void> =>
1091 Effect.uninterruptible(

Callers

nothing calls this directly

Calls 6

makeSubscriptionUnsafeFunction · 0.85
unsubscribeFunction · 0.85
addFinalizerMethod · 0.80
getMethod · 0.65
pipeMethod · 0.65
closeMethod · 0.65

Tested by

no test coverage detected