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

Function poll

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

Source from the content-addressed store, hash-verified

736 * @since 2.0.0
737 */
738export 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.

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected