| 796 | * @since 2.0.0 |
| 797 | */ |
| 798 | export 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. |