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

Function takeAll

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

Source from the content-addressed store, hash-verified

796 * @since 2.0.0
797 */
798export const takeAll = <A, E>(self: TxDequeue<A, E>): Effect.Effect<Arr.NonEmptyArray<A>, E> =>
799 Effect.gen(function*() {
800 const state = yield* TxRef.get(self.stateRef)
801
802 // Handle done queue
803 if (state._tag === "Done") {
804 return yield* Effect.failCause(state.cause)
805 }
806
807 // Wait if empty - same pattern as take()
808 if (yield* isEmpty(self)) {
809 return yield* Effect.txRetry
810 }
811
812 const chunk = yield* TxChunk.get(self.items)
813
814 // Take all items (guaranteed non-empty due to isEmpty check above)
815 const items = Chunk.toArray(chunk) as Arr.NonEmptyArray<A>
816 yield* TxChunk.set(self.items, Chunk.empty())
817
818 // Check if we need to transition Closing → Done
819 if (state._tag === "Closing") {
820 yield* TxRef.set(self.stateRef, { _tag: "Done", cause: state.cause })
821 }
822
823 return items
824 }).pipe(Effect.tx)
825
826/**
827 * Takes up to `n` items from the queue in a single transaction.

Callers

nothing calls this directly

Calls 5

toArrayMethod · 0.80
isEmptyFunction · 0.70
pipeMethod · 0.65
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected