/** * Runs the specified effect if this effect is terminated, either because of a * defect or because of interruption. * * @tsplus static effect/core/io/Effect.Aspects onTermination * @tsplus pipeable effect/core/io/Effect onTermination */ export function onTermination(cleanup: (cause: Cause) => Effect) { return (self: Effect): Effect => Effect.acquireUseReleaseExit( Effect.unit, () => self, (_, exit) => exit._tag === "Failure" ? exit.cause.failureOrCause.fold(() => Effect.unit, cleanup) : Effect.unit ) }