| 715 | * @since 2.0.0 |
| 716 | */ |
| 717 | export const poll = <A, E>(self: TxDequeue<A, E>): Effect.Effect<Option.Option<A>> => |
| 718 | Effect.gen(function*() { |
| 719 | const state = yield* TxRef.get(self.stateRef) |
| 720 | if (state._tag === "Done") { |
| 721 | return Option.none() |
| 722 | } |
| 723 | |
| 724 | const chunk = yield* TxChunk.get(self.items) |
| 725 | const head = Chunk.head(chunk) |
| 726 | if (Option.isNone(head)) { |
| 727 | return Option.none() |
| 728 | } |
| 729 | |
| 730 | yield* TxChunk.drop(self.items, 1) |
| 731 | |
| 732 | if (state._tag === "Closing" && (yield* isEmpty(self))) { |
| 733 | yield* TxRef.set(self.stateRef, { _tag: "Done", cause: state.cause }) |
| 734 | } |
| 735 | |
| 736 | return Option.some(head.value) |
| 737 | }).pipe(Effect.tx) |
| 738 | |
| 739 | /** |
| 740 | * Takes all items from the queue. Blocks if the queue is empty. |