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

Function poll

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

Source from the content-addressed store, hash-verified

715 * @since 2.0.0
716 */
717export 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.

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected