| 736 | * @since 2.0.0 |
| 737 | */ |
| 738 | export const poll = <A, E>(self: TxDequeue<A, E>): Effect.Effect<Option.Option<A>> => |
| 739 | Effect.gen(function*() { |
| 740 | const state = yield* TxRef.get(self.stateRef) |
| 741 | if (state._tag === "Done") { |
| 742 | return Option.none() |
| 743 | } |
| 744 | |
| 745 | const chunk = yield* TxChunk.get(self.items) |
| 746 | const head = Chunk.head(chunk) |
| 747 | if (Option.isNone(head)) { |
| 748 | return Option.none() |
| 749 | } |
| 750 | |
| 751 | yield* TxChunk.drop(self.items, 1) |
| 752 | |
| 753 | if (state._tag === "Closing" && (yield* isEmpty(self))) { |
| 754 | yield* TxRef.set(self.stateRef, { _tag: "Done", cause: state.cause }) |
| 755 | } |
| 756 | |
| 757 | return Option.some(head.value) |
| 758 | }).pipe(Effect.tx) |
| 759 | |
| 760 | /** |
| 761 | * Takes all items from the queue. Blocks if the queue is empty. |