<A extends Request.Any>(options: {
readonly batchKey: (request: Request.Entry<A>) => unknown
readonly preCheck?: ((entry: Request.Entry<A>) => boolean) | undefined
readonly delay: Effect.Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
}): RequestResolver<A>Creates a request resolver with fine-grained control over its behavior.
When to use
Use when you need to supply the resolver batching primitives directly, including the batch key, optional pre-check, delay effect, collection cutoff, and batch runner.
Details
batchKey groups request entries, delay schedules batch execution,
collectWhile can end collection early, and runAll receives a non-empty
batch for one key.
Gotchas
Accepted entries must be completed. If runAll succeeds with incomplete
entries, waiting requests fail. If preCheck returns false, the entry is
not batched, so it must be completed or linked to another completion path.
export const const makeWith: <
A extends Request.Any
>(options: {
readonly batchKey: (
request: Request.Entry<A>
) => unknown
readonly preCheck?:
| ((entry: Request.Entry<A>) => boolean)
| undefined
readonly delay: Effect.Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
}) => RequestResolver<A>
Creates a request resolver with fine-grained
control over its behavior.
When to use
Use when you need to supply the resolver batching primitives directly,
including the batch key, optional pre-check, delay effect, collection cutoff,
and batch runner.
Details
batchKey groups request entries, delay schedules batch execution,
collectWhile can end collection early, and runAll receives a non-empty
batch for one key.
Gotchas
Accepted entries must be completed. If runAll succeeds with incomplete
entries, waiting requests fail. If preCheck returns false, the entry is
not batched, so it must be completed or linked to another completion path.
makeWith = <function (type parameter) A in <A extends Request.Any>(options: {
readonly batchKey: (request: Request.Entry<A>) => unknown;
readonly preCheck?: ((entry: Request.Entry<A>) => boolean) | undefined;
readonly delay: Effect.Effect<void>;
readonly collectWhile: (requests: ReadonlySet<Request.Entry<A>>) => boolean;
readonly runAll: (entries: NonEmptyArray<Request.Entry<A>>, key: unknown) => Effect.Effect<void, Request.Error<A>>;
}): RequestResolver<A>
A extends import RequestRequest.type Any = Request.Request<any, any, any>Alias for any Request, regardless of its success, error, or service
requirements.
When to use
Use as a generic constraint for APIs that accept any request while preserving
each concrete request's success, error, and service types.
Any>(options: {
readonly batchKey: (
request: Request.Entry<A>
) => unknown
readonly preCheck?:
| ((entry: Request.Entry<A>) => boolean)
| undefined
readonly delay: Effect.Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
}
options: {
readonly batchKey: (request: Request.Entry<A>) => unknownbatchKey: (request: Request.Entry<A>(parameter) request: {
request: R;
context: Context.Context<[R] extends [Request<infer _A, infer _E, infer _R>] ? _R : never>;
uninterruptible: boolean;
completeUnsafe: (exit: Exit.Exit<[A] extends [Request.Request<infer _A, infer _E, infer _R>] ? _A : never, [A] extends [Request.Request<infer _A, infer _E, infer _R>] ? _E : never>) => void;
}
request: import RequestRequest.interface Entry<out R>A pending request handed to a RequestResolver.
Details
An entry contains the original request, the fiber context needed to run it,
an uninterruptible flag used by batching and caching internals, and the
completeUnsafe callback used by resolvers to supply the final Exit.
Entry<function (type parameter) A in <A extends Request.Any>(options: {
readonly batchKey: (request: Request.Entry<A>) => unknown;
readonly preCheck?: ((entry: Request.Entry<A>) => boolean) | undefined;
readonly delay: Effect.Effect<void>;
readonly collectWhile: (requests: ReadonlySet<Request.Entry<A>>) => boolean;
readonly runAll: (entries: NonEmptyArray<Request.Entry<A>>, key: unknown) => Effect.Effect<void, Request.Error<A>>;
}): RequestResolver<A>
A>) => unknown
readonly preCheck?: | ((entry: Request.Entry<A>) => boolean)
| undefined
preCheck?: ((entry: Request.Entry<A>(parameter) entry: {
request: R;
context: Context.Context<[R] extends [Request<infer _A, infer _E, infer _R>] ? _R : never>;
uninterruptible: boolean;
completeUnsafe: (exit: Exit.Exit<[A] extends [Request.Request<infer _A, infer _E, infer _R>] ? _A : never, [A] extends [Request.Request<infer _A, infer _E, infer _R>] ? _E : never>) => void;
}
entry: import RequestRequest.interface Entry<out R>A pending request handed to a RequestResolver.
Details
An entry contains the original request, the fiber context needed to run it,
an uninterruptible flag used by batching and caching internals, and the
completeUnsafe callback used by resolvers to supply the final Exit.
Entry<function (type parameter) A in <A extends Request.Any>(options: {
readonly batchKey: (request: Request.Entry<A>) => unknown;
readonly preCheck?: ((entry: Request.Entry<A>) => boolean) | undefined;
readonly delay: Effect.Effect<void>;
readonly collectWhile: (requests: ReadonlySet<Request.Entry<A>>) => boolean;
readonly runAll: (entries: NonEmptyArray<Request.Entry<A>>, key: unknown) => Effect.Effect<void, Request.Error<A>>;
}): RequestResolver<A>
A>) => boolean) | undefined
readonly delay: Effect.Effect<void>(property) delay: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
delay: import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
collectWhile: (requests: ReadonlySet<Request.Entry<A>>requests: interface ReadonlySet<T>ReadonlySet<import RequestRequest.interface Entry<out R>A pending request handed to a RequestResolver.
Details
An entry contains the original request, the fiber context needed to run it,
an uninterruptible flag used by batching and caching internals, and the
completeUnsafe callback used by resolvers to supply the final Exit.
Entry<function (type parameter) A in <A extends Request.Any>(options: {
readonly batchKey: (request: Request.Entry<A>) => unknown;
readonly preCheck?: ((entry: Request.Entry<A>) => boolean) | undefined;
readonly delay: Effect.Effect<void>;
readonly collectWhile: (requests: ReadonlySet<Request.Entry<A>>) => boolean;
readonly runAll: (entries: NonEmptyArray<Request.Entry<A>>, key: unknown) => Effect.Effect<void, Request.Error<A>>;
}): RequestResolver<A>
A>>) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
runAll: (entries: NonEmptyArray<Request.Entry<A>>(parameter) entries: {
0: Request.Entry<A>;
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
pop: () => Request.Entry<A> | undefined;
push: (...items: Array<Request.Entry<A>>) => number;
concat: { (...items: Array<ConcatArray<Request.Entry<A>>>): Array<Request.Entry<A>>; (...items: Array<Request.Entry<A> | ConcatArray<Request.Entry<A>>>): Array<Request.Entry<A>> };
join: (separator?: string) => string;
reverse: () => Array<Request.Entry<A>>;
shift: () => Request.Entry<A> | undefined;
slice: (start?: number, end?: number) => Array<Request.Entry<A>>;
sort: (compareFn?: ((a: Request.Entry<A>, b: Request.Entry<A>) => number) | undefined) => [Request.Entry<A>, ...Request.Entry<A>[]];
splice: { (start: number, deleteCount?: number): Array<Request.Entry<A>>; (start: number, deleteCount: number, ...items: Array<Request.Entry<A>>): Array<Request.Entry<A>> };
unshift: (...items: Array<Request.Entry<A>>) => number;
indexOf: (searchElement: Request.Entry<A>, fromIndex?: number) => number;
lastIndexOf: (searchElement: Request.Entry<A>, fromIndex?: number) => number;
every: { (predicate: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => value is S, thisArg?: any): this is S[]; (predicate: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => unknown, thisArg?: a…;
some: (predicate: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => void, thisArg?: any) => void;
map: (callbackfn: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => value is S, thisArg?: any): Array<S>; (predicate: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => unknown, thisArg?: any)…;
reduce: { (callbackfn: (previousValue: Request.Entry<A>, currentValue: Request.Entry<A>, currentIndex: number, array: Array<Request.Entry<A>>) => Request.Entry<A>): Request.Entry<A>; (callbackfn: (previousValue: Request.Entry<A>, currentValue: Req…;
reduceRight: { (callbackfn: (previousValue: Request.Entry<A>, currentValue: Request.Entry<A>, currentIndex: number, array: Array<Request.Entry<A>>) => Request.Entry<A>): Request.Entry<A>; (callbackfn: (previousValue: Request.Entry<A>, currentValue: Req…;
find: { (predicate: (value: Request.Entry<A>, index: number, obj: Array<Request.Entry<A>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Request.Entry<A>, index: number, obj: Array<Request.Entry<A>>) => unknown, thisArg?: any…;
findIndex: (predicate: (value: Request.Entry<A>, index: number, obj: Array<Request.Entry<A>>) => unknown, thisArg?: any) => number;
fill: (value: Request.Entry<A>, start?: number, end?: number) => [Request.Entry<A>, ...Request.Entry<A>[]];
copyWithin: (target: number, start: number, end?: number) => [Request.Entry<A>, ...Request.Entry<A>[]];
entries: () => ArrayIterator<[number, Request.Entry<A>]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<Request.Entry<A>>;
includes: (searchElement: Request.Entry<A>, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => Request.Entry<A> | undefined;
findLast: { (predicate: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => value is S, thisArg?: any): S | undefined; (predicate: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => unknown, thisArg?:…;
findLastIndex: (predicate: (value: Request.Entry<A>, index: number, array: Array<Request.Entry<A>>) => unknown, thisArg?: any) => number;
toReversed: () => Array<Request.Entry<A>>;
toSorted: (compareFn?: ((a: Request.Entry<A>, b: Request.Entry<A>) => number) | undefined) => Array<Request.Entry<A>>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<Request.Entry<A>>): Array<Request.Entry<A>>; (start: number, deleteCount?: number): Array<Request.Entry<A>> };
with: (index: number, value: Request.Entry<A>) => Array<Request.Entry<A>>;
}
entries: type NonEmptyArray<A> = [A, ...A[]]A mutable array guaranteed to have at least one element.
When to use
Use when mutation is acceptable and non-emptiness must be tracked at the type
level.
Details
This is the mutable counterpart of
NonEmptyReadonlyArray
. Most Array
module functions return NonEmptyArray when the result is guaranteed
non-empty.
Example (Typing a mutable non-empty array)
import type { Array } from "effect"
const nonEmpty: Array.NonEmptyArray<number> = [1, 2, 3]
nonEmpty.push(4)
NonEmptyArray<import RequestRequest.interface Entry<out R>A pending request handed to a RequestResolver.
Details
An entry contains the original request, the fiber context needed to run it,
an uninterruptible flag used by batching and caching internals, and the
completeUnsafe callback used by resolvers to supply the final Exit.
Entry<function (type parameter) A in <A extends Request.Any>(options: {
readonly batchKey: (request: Request.Entry<A>) => unknown;
readonly preCheck?: ((entry: Request.Entry<A>) => boolean) | undefined;
readonly delay: Effect.Effect<void>;
readonly collectWhile: (requests: ReadonlySet<Request.Entry<A>>) => boolean;
readonly runAll: (entries: NonEmptyArray<Request.Entry<A>>, key: unknown) => Effect.Effect<void, Request.Error<A>>;
}): RequestResolver<A>
A>>, key: unknownkey: unknown) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<void, import RequestRequest.type Error<
T extends Request.Request<any, any, any>
> = [T] extends [
Request.Request<infer _A, infer _E, infer _R>
]
? _E
: never
A utility type to extract the error type from a Request.
Example (Extracting a request error type)
import type { Request } from "effect"
interface GetUser extends Request.Request<string, Error> {
readonly id: number
}
// Extract the error type from a Request using the utility
type UserError = Request.Error<GetUser> // Error
Error<function (type parameter) A in <A extends Request.Any>(options: {
readonly batchKey: (request: Request.Entry<A>) => unknown;
readonly preCheck?: ((entry: Request.Entry<A>) => boolean) | undefined;
readonly delay: Effect.Effect<void>;
readonly collectWhile: (requests: ReadonlySet<Request.Entry<A>>) => boolean;
readonly runAll: (entries: NonEmptyArray<Request.Entry<A>>, key: unknown) => Effect.Effect<void, Request.Error<A>>;
}): RequestResolver<A>
A>>
}): interface RequestResolver<in A extends Request.Any>A resolver that executes and completes batched Request entries.
Details
A resolver controls how requests are grouped, delayed, optionally
pre-checked, and finally run. Its runAll method receives a non-empty batch
of Request.Entry values for a single batch key and must complete every
received entry, usually by calling completeUnsafe or one of the Request
completion helpers.
Gotchas
If a resolver finishes without completing an entry, the waiting request fails
because the resolver did not supply a result.
Example (Defining a request resolver)
import { Effect, Exit, RequestResolver } from "effect"
import type { Request } from "effect"
interface GetUserRequest extends Request.Request<string, Error> {
readonly _tag: "GetUserRequest"
readonly id: number
}
// In practice, you would typically use RequestResolver.make() instead
const resolver = RequestResolver.make<GetUserRequest>((entries) =>
Effect.sync(() => {
for (const entry of entries) {
entry.completeUnsafe(Exit.succeed(`User ${entry.request.id}`))
}
})
)
Namespace containing type-level helpers associated with RequestResolver.
RequestResolver<function (type parameter) A in <A extends Request.Any>(options: {
readonly batchKey: (request: Request.Entry<A>) => unknown;
readonly preCheck?: ((entry: Request.Entry<A>) => boolean) | undefined;
readonly delay: Effect.Effect<void>;
readonly collectWhile: (requests: ReadonlySet<Request.Entry<A>>) => boolean;
readonly runAll: (entries: NonEmptyArray<Request.Entry<A>>, key: unknown) => Effect.Effect<void, Request.Error<A>>;
}): RequestResolver<A>
A> => {
const const self: anyself = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)Creates an object that has the specified prototype or that has null prototype.
create(const RequestResolverProto: {
"~effect/RequestResolver": {
_A: <A>(a: A) => A
_R: <A>(a: A) => A
}
pipe(): unknown
}
RequestResolverProto)
const self: anyself.batchKey = options: {
readonly batchKey: (
request: Request.Entry<A>
) => unknown
readonly preCheck?:
| ((entry: Request.Entry<A>) => boolean)
| undefined
readonly delay: Effect.Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
}
options.batchKey: (request: Request.Entry<A>) => unknownbatchKey
const self: anyself.preCheck = options: {
readonly batchKey: (
request: Request.Entry<A>
) => unknown
readonly preCheck?:
| ((entry: Request.Entry<A>) => boolean)
| undefined
readonly delay: Effect.Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
}
options.preCheck?: | ((entry: Request.Entry<A>) => boolean)
| undefined
preCheck
const self: anyself.delay = options: {
readonly batchKey: (
request: Request.Entry<A>
) => unknown
readonly preCheck?:
| ((entry: Request.Entry<A>) => boolean)
| undefined
readonly delay: Effect.Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
}
options.delay: Effect.Effect<void>(property) delay: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
delay
const self: anyself.collectWhile = options: {
readonly batchKey: (
request: Request.Entry<A>
) => unknown
readonly preCheck?:
| ((entry: Request.Entry<A>) => boolean)
| undefined
readonly delay: Effect.Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
}
options.collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
collectWhile
const self: anyself.runAll = options: {
readonly batchKey: (
request: Request.Entry<A>
) => unknown
readonly preCheck?:
| ((entry: Request.Entry<A>) => boolean)
| undefined
readonly delay: Effect.Effect<void>
readonly collectWhile: (
requests: ReadonlySet<Request.Entry<A>>
) => boolean
readonly runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
}
options.runAll: (
entries: NonEmptyArray<Request.Entry<A>>,
key: unknown
) => Effect.Effect<void, Request.Error<A>>
runAll
return const self: anyself
}