Home

ZManaged

ZManaged is a data type in the ZIO ecosystem that represents a resource with an explicit lifecycle. It encapsulates the actions to acquire a resource along with a release or finalization action, ensuring that the resource is released when it is no longer in use, even in the face of errors or interruptions. ZManaged is parameterized as ZManaged[R, E, A], where R is the required environment, E is the error type, and A is the resource type.

The core idea is to separate acquisition from release and to compose resource lifecycles in a safe,

ZManaged offers constructors and combinators to build and transform resources. You can create a managed from

Common use cases include managing database connections, file handles, sockets, and thread pools. By providing guarantees

See also: ZIO, resource safety, managed resources.

deterministic
way.
A
ZManaged
value
describes
how
to
obtain
an
A
from
an
environment
R
and
how
to
release
A
afterward.
Rather
than
performing
acquisition
and
cleanup
in
a
single
effect,
ZManaged
provides
a
structured
way
to
compose
multiple
resources
and
manage
their
lifetimes.
The
primary
operation
for
using
a
ZManaged
is
a
scoped
“use”
(or
equivalent)
that
runs
a
function
with
the
acquired
resource
and
guarantees
the
release
action
will
run
after
the
function
completes,
regardless
of
success
or
failure.
a
pair
of
acquisition
and
release
actions,
lift
ordinary
effects
into
managed
context,
and
transform
or
map
the
resource.
It
can
also
be
combined
with
other
managed
resources
to
form
composite
lifecycles,
releasing
resources
in
a
well-defined
order.
about
finalization,
ZManaged
helps
prevent
resource
leaks
and
simplifies
error
handling
in
effectful
programs.