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

Function asyncQueue

packages/effect/src/Channel.ts:492–511  ·  view source on GitHub ↗
(
  scope: Scope.Scope,
  f: (queue: Queue.Queue<A, E | Cause.Done>) => Effect.Effect<unknown, E, R | Scope.Scope>,
  options?: {
    readonly bufferSize?: number | undefined
    readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
  }
)

Source from the content-addressed store, hash-verified

490export const DefaultChunkSize: number = 4096
491
492const asyncQueue = <A, E = never, R = never>(
493 scope: Scope.Scope,
494 f: (queue: Queue.Queue<A, E | Cause.Done>) => Effect.Effect<unknown, E, R | Scope.Scope>,
495 options?: {
496 readonly bufferSize?: number | undefined
497 readonly strategy?: "sliding" | "dropping" | "suspend" | undefined
498 }
499) =>
500 Queue.make<A, E | Cause.Done>({
501 capacity: options?.bufferSize,
502 strategy: options?.strategy
503 }).pipe(
504 Effect.tap((queue) => Scope.addFinalizer(scope, Queue.shutdown(queue))),
505 Effect.tap((queue) =>
506 Scope.provide(f(queue), scope).pipe(
507 Effect.catchCause((cause) => Queue.failCause(queue, cause)),
508 Effect.forkIn(scope, { startImmediately: true })
509 )
510 )
511 )
512
513/**
514 * Creates a `Channel` that interacts with a callback function using a queue.

Callers 2

callbackFunction · 0.85
callbackArrayFunction · 0.85

Calls 6

addFinalizerMethod · 0.80
pipeMethod · 0.65
makeMethod · 0.65
fFunction · 0.50
shutdownMethod · 0.45
provideMethod · 0.45

Tested by

no test coverage detected