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

Function take

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

Source from the content-addressed store, hash-verified

1142 * @since 4.0.0
1143 */
1144export const take = <A>(self: Subscription<A>): Effect.Effect<A> =>
1145 Effect.suspend(() => {
1146 if (self.shutdownFlag.current) {
1147 return Effect.interrupt
1148 }
1149 if (self.replayWindow.remaining > 0) {
1150 const message = self.replayWindow.take()!
1151 return Effect.succeed(message)
1152 }
1153 const message = self.pollers.length === 0
1154 ? self.subscription.poll()
1155 : MutableList.Empty
1156 if (message === MutableList.Empty) {
1157 return pollForItem(self)
1158 } else {
1159 self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers)
1160 return Effect.succeed(message)
1161 }
1162 })
1163
1164/**
1165 * Takes all available messages from the subscription, suspending if no items

Callers 1

takeRemainderLoopFunction · 0.70

Calls 5

pollForItemFunction · 0.85
takeMethod · 0.65
pollMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected