<A>(value: A): SynchronizedRef<A>Creates a SynchronizedRef synchronously from an initial value.
When to use
Use when you need synchronous SynchronizedRef construction outside an
Effect workflow.
export const const makeUnsafe: <A>(
value: A
) => SynchronizedRef<A>
Creates a SynchronizedRef synchronously from an initial value.
When to use
Use when you need synchronous SynchronizedRef construction outside an
Effect workflow.
makeUnsafe = <function (type parameter) A in <A>(value: A): SynchronizedRef<A>A>(value: Avalue: function (type parameter) A in <A>(value: A): SynchronizedRef<A>A): interface SynchronizedRef<in out A>A mutable reference whose update and modify operations are serialized with an
internal semaphore, including effectful transformations.
When to use
Use when shared state may be updated by multiple fibers and each update,
including effectful state transitions, must observe one current value and run
one at a time.
SynchronizedRef<function (type parameter) A in <A>(value: A): SynchronizedRef<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 Proto: {
"~effect/SynchronizedRef": string
toJSON(this: SynchronizedRef<any>): {
_id: string
value: any
}
pipe(): unknown
toString(): string
[NodeInspectSymbol](): any
}
Proto)
const self: anyself.semaphore = import SemaphoreSemaphore.const makeUnsafe: (
permits: number
) => Semaphore
Creates a Semaphore synchronously with the specified total
number of permits.
When to use
Use to construct a semaphore synchronously when an immediate value is
required outside an Effect workflow.
Example (Creating an unsafe semaphore)
import { Effect, Semaphore } from "effect"
const semaphore = Semaphore.makeUnsafe(3)
const task = (id: number) =>
semaphore.withPermits(1)(
Effect.gen(function*() {
yield* Effect.log(`Task ${id} started`)
yield* Effect.sleep("1 second")
yield* Effect.log(`Task ${id} completed`)
})
)
// Only 3 tasks can run concurrently
const program = Effect.all([
task(1),
task(2),
task(3),
task(4),
task(5)
], { concurrency: "unbounded" })
makeUnsafe(1)
const self: anyself.backing = import RefRef.const makeUnsafe: <A>(value: A) => Ref<A>Creates a new Ref with the specified initial value (unsafe version).
When to use
Use when you need immediate synchronous construction and can guarantee
that creating the Ref outside of Effect is safe.
Gotchas
Prefer Ref.make for Effect-wrapped creation in Effect programs.
Example (Creating a ref unsafely)
import { Ref } from "effect"
// Create a ref directly without Effect
const counter = Ref.makeUnsafe(0)
// Get the current value
const value = Ref.getUnsafe(counter)
console.log(value) // 0
// Note: This is unsafe and should be used carefully
// Prefer Ref.make for Effect-wrapped creation
makeUnsafe(value: Avalue)
return const self: anyself
}