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

Function take

packages/effect/src/TxQueue.ts:681–710  ·  view source on GitHub ↗
(self: TxDequeue<A, E>)

Source from the content-addressed store, hash-verified

679 * @since 2.0.0
680 */
681export const take = <A, E>(self: TxDequeue<A, E>): Effect.Effect<A, E> =>
682 Effect.gen(function*() {
683 const state = yield* TxRef.get(self.stateRef)
684
685 // Check if queue is done - forward the cause directly
686 if (state._tag === "Done") {
687 return yield* Effect.failCause(state.cause)
688 }
689
690 // If no items available, retry transaction
691 if (yield* isEmpty(self)) {
692 return yield* Effect.txRetry
693 }
694
695 // Take item from queue
696 const chunk = yield* TxChunk.get(self.items)
697 const head = Chunk.head(chunk)
698 if (Option.isNone(head)) {
699 return yield* Effect.txRetry
700 }
701
702 yield* TxChunk.drop(self.items, 1)
703
704 // Check if we need to transition Closing → Done
705 if (state._tag === "Closing" && (yield* isEmpty(self))) {
706 yield* TxRef.set(self.stateRef, { _tag: "Done", cause: state.cause })
707 }
708
709 return head.value
710 }).pipe(Effect.tx)
711
712/**
713 * Tries to take an item from the queue without blocking.

Callers

nothing calls this directly

Calls 5

isEmptyFunction · 0.70
pipeMethod · 0.65
getMethod · 0.65
dropMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected