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

Function take

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

Source from the content-addressed store, hash-verified

1347 * @since 4.0.0
1348 */
1349export const take = <A>(self: Subscription<A>): Effect.Effect<A> =>
1350 Effect.suspend(() => {
1351 if (self.shutdownFlag.current) {
1352 return Effect.interrupt
1353 }
1354 if (self.replayWindow.remaining > 0) {
1355 const message = self.replayWindow.take()!
1356 return Effect.succeed(message)
1357 }
1358 const message = self.pollers.length === 0
1359 ? self.subscription.poll()
1360 : MutableList.Empty
1361 if (message === MutableList.Empty) {
1362 return pollForItem(self)
1363 } else {
1364 self.strategy.onPubSubEmptySpaceUnsafe(self.pubsub, self.subscribers)
1365 return Effect.succeed(message)
1366 }
1367 })
1368
1369/**
1370 * 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