<A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>Creates a scoped effect by providing access to the scope.
When to use
Use when resource acquisition needs direct access to the scope being created, for example to register finalizers manually.
Example (Working with an explicit scope)
import { Console, Effect, Scope } from "effect"
const program = Effect.scopedWith((scope) =>
Effect.gen(function*() {
yield* Console.log("Inside scoped context")
// Manually add a finalizer to the scope
yield* Scope.addFinalizer(scope, Console.log("Manual finalizer"))
// Create a scoped resource
const resource = yield* Effect.scoped(
Effect.acquireRelease(
Console.log("Acquiring resource").pipe(Effect.as("resource")),
() => Console.log("Releasing resource")
)
)
return resource
})
)
Effect.runPromise(program).then(console.log)
// Output:
// Inside scoped context
// Acquiring resource
// resource
// Releasing resource
// Manual finalizerexport const const scopedWith: <A, E, R>(
f: (scope: Scope) => Effect<A, E, R>
) => Effect<A, E, R>
Creates a scoped effect by providing access to the scope.
When to use
Use when resource acquisition needs direct access to the scope being created,
for example to register finalizers manually.
Example (Working with an explicit scope)
import { Console, Effect, Scope } from "effect"
const program = Effect.scopedWith((scope) =>
Effect.gen(function*() {
yield* Console.log("Inside scoped context")
// Manually add a finalizer to the scope
yield* Scope.addFinalizer(scope, Console.log("Manual finalizer"))
// Create a scoped resource
const resource = yield* Effect.scoped(
Effect.acquireRelease(
Console.log("Acquiring resource").pipe(Effect.as("resource")),
() => Console.log("Releasing resource")
)
)
return resource
})
)
Effect.runPromise(program).then(console.log)
// Output:
// Inside scoped context
// Acquiring resource
// resource
// Releasing resource
// Manual finalizer
scopedWith: <function (type parameter) A in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>R>(
f: (scope: Scope) => Effect<A, E, R>f: (scope: Scope(parameter) scope: {
strategy: "sequential" | "parallel";
state: State.Open | State.Closed | State.Empty;
}
scope: Scope) => 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<function (type parameter) A in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>R>
) => 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<function (type parameter) A in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>A, function (type parameter) E in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>E, function (type parameter) R in <A, E, R>(f: (scope: Scope) => Effect<A, E, R>): Effect<A, E, R>R> = import internalinternal.const scopedWith: <A, E, R>(
f: (
scope: Scope.Scope
) => Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
scopedWith