{
  "id": "@typed/fx/Fx#onInterrupt",
  "canonicalId": "@typed/fx/Fx#onInterrupt",
  "symbol": {
    "id": "@typed/fx/Fx#onInterrupt",
    "packageName": "@typed/fx",
    "moduleName": "Fx",
    "exportName": "onInterrupt",
    "kind": "constant",
    "signatures": [
      "export declare const onInterrupt: {\n    <XE, XR>(finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): <A, E, R>(self: Fx<A, E, R>) => Fx<A, E | XE, R | XR>;\n    <A, E, R, XE, XR>(self: Fx<A, E, R>, finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): Fx<A, E | XE, R | XR>;\n};"
    ],
    "summary": "Runs a finalizer when the Fx reports or externally receives interruption.",
    "sections": {
      "Why": "Cancellation-specific cleanup should not run for success or ordinary typed\nfailure. The interruptor IDs retain Effect's information about which fibers\nrequested cancellation.",
      "Ownership and lifetime": "An interrupt-only Cause reported by the source invokes the finalizer before\nthat Cause is delivered; finalizer failure is combined with it. External\ninterruption of the running fiber also invokes the finalizer, suppressing its\nfailure to preserve cancellation. Those paths are tracked separately: if an\nexternal interruption arrives while reported-Cause handling is still active,\nthe finalizer can run once for each path. Successful and non-interrupt failures\ndo not invoke it. A finalizer captured while constructing an Fx is shared by\nevery run of that Fx; create mutable cleanup state lazily inside `gen` or\n`genScoped` when each subscription must own a distinct resource."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport { onInterrupt } from \"@typed/fx/Fx\"\nimport { interrupt } from \"@typed/fx/Fx\"\n\nconst observed = onInterrupt(\n  interrupt(1),\n  (ids) => Effect.log(`interrupted by ${ids.size}`)\n)"
      },
      {
        "language": "text",
        "code": "Keep the finalizer idempotent when both interrupt paths are possible\n```ts\nimport { Effect } from \"effect\"\nimport { gen } from \"@typed/fx/Fx\"\nimport { onInterrupt } from \"@typed/fx/Fx\"\nimport { interrupt } from \"@typed/fx/Fx\"\n\nconst observed = gen(function* () {\n// `gen` creates this controller separately for every subscription.\nconst controller = yield* Effect.sync(() => new AbortController())\nreturn onInterrupt(\ninterrupt(1),\nEffect.sync(() => controller.abort()) // `abort` is idempotent.\n)\n})\n```"
      }
    ],
    "relations": [],
    "source": {
      "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
      "line": 73
    },
    "since": "1.0.0",
    "category": "Resource lifetime"
  },
  "exposure": {
    "recordKind": "declaration",
    "id": "@typed/fx/Fx#onInterrupt",
    "packageName": "@typed/fx",
    "packageVersion": "2.0.0-beta.7",
    "moduleName": "Fx",
    "consumerSpecifier": "@typed/fx/Fx",
    "exportName": "onInterrupt",
    "qualifiedName": "onInterrupt",
    "declarationKey": "declaration:dc32710bfdda53e23249a6b2",
    "family": "variable",
    "signatures": [
      "export declare const onInterrupt: {\n    <XE, XR>(finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): <A, E, R>(self: Fx<A, E, R>) => Fx<A, E | XE, R | XR>;\n    <A, E, R, XE, XR>(self: Fx<A, E, R>, finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): Fx<A, E | XE, R | XR>;\n};"
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
        "start": {
          "line": 73,
          "column": 14
        },
        "end": {
          "line": 132,
          "column": 2
        }
      },
      {
        "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
        "start": {
          "line": 74,
          "column": 3
        },
        "end": {
          "line": 78,
          "column": 60
        }
      },
      {
        "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
        "start": {
          "line": 80,
          "column": 3
        },
        "end": {
          "line": 85,
          "column": 28
        }
      }
    ],
    "aliases": [
      "@typed/fx#Fx.onInterrupt"
    ],
    "isAlias": false,
    "static": false
  },
  "declaration": {
    "declarationKey": "declaration:dc32710bfdda53e23249a6b2",
    "name": "onInterrupt",
    "family": "variable",
    "facets": [
      {
        "family": "variable",
        "syntaxKind": "VariableDeclaration",
        "signatures": [
          "export declare const onInterrupt: {\n    <XE, XR>(finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): <A, E, R>(self: Fx<A, E, R>) => Fx<A, E | XE, R | XR>;\n    <A, E, R, XE, XR>(self: Fx<A, E, R>, finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): Fx<A, E | XE, R | XR>;\n};"
        ],
        "typeParameters": [],
        "sourceSpans": [
          {
            "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
            "start": {
              "line": 73,
              "column": 14
            },
            "end": {
              "line": 132,
              "column": 2
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      },
      {
        "family": "call-signature",
        "syntaxKind": "CallSignature",
        "signatures": [
          "<XE, XR>(finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): <A, E, R>(self: Fx<A, E, R>) => Fx<A, E | XE, R | XR>;",
          "<A, E, R, XE, XR>(self: Fx<A, E, R>, finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): Fx<A, E | XE, R | XR>;"
        ],
        "typeParameters": [
          "XE",
          "XR",
          "A",
          "E",
          "R"
        ],
        "sourceSpans": [
          {
            "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
            "start": {
              "line": 74,
              "column": 3
            },
            "end": {
              "line": 78,
              "column": 60
            }
          },
          {
            "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
            "start": {
              "line": 80,
              "column": 3
            },
            "end": {
              "line": 85,
              "column": 28
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      }
    ],
    "signatures": [
      "export declare const onInterrupt: {\n    <XE, XR>(finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): <A, E, R>(self: Fx<A, E, R>) => Fx<A, E | XE, R | XR>;\n    <A, E, R, XE, XR>(self: Fx<A, E, R>, finalizer: Effect.Effect<void, XE, XR> | ((interruptors: ReadonlySet<number>) => Effect.Effect<void, XE, XR>)): Fx<A, E | XE, R | XR>;\n};"
    ],
    "typeParameters": [
      "XE",
      "XR",
      "A",
      "E",
      "R"
    ],
    "summary": "Runs a finalizer when the Fx reports or externally receives interruption.",
    "sections": {
      "Why": "Cancellation-specific cleanup should not run for success or ordinary typed\nfailure. The interruptor IDs retain Effect's information about which fibers\nrequested cancellation.",
      "Ownership and lifetime": "An interrupt-only Cause reported by the source invokes the finalizer before\nthat Cause is delivered; finalizer failure is combined with it. External\ninterruption of the running fiber also invokes the finalizer, suppressing its\nfailure to preserve cancellation. Those paths are tracked separately: if an\nexternal interruption arrives while reported-Cause handling is still active,\nthe finalizer can run once for each path. Successful and non-interrupt failures\ndo not invoke it. A finalizer captured while constructing an Fx is shared by\nevery run of that Fx; create mutable cleanup state lazily inside `gen` or\n`genScoped` when each subscription must own a distinct resource."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport { onInterrupt } from \"@typed/fx/Fx\"\nimport { interrupt } from \"@typed/fx/Fx\"\n\nconst observed = onInterrupt(\n  interrupt(1),\n  (ids) => Effect.log(`interrupted by ${ids.size}`)\n)"
      },
      {
        "language": "text",
        "code": "Keep the finalizer idempotent when both interrupt paths are possible\n```ts\nimport { Effect } from \"effect\"\nimport { gen } from \"@typed/fx/Fx\"\nimport { onInterrupt } from \"@typed/fx/Fx\"\nimport { interrupt } from \"@typed/fx/Fx\"\n\nconst observed = gen(function* () {\n// `gen` creates this controller separately for every subscription.\nconst controller = yield* Effect.sync(() => new AbortController())\nreturn onInterrupt(\ninterrupt(1),\nEffect.sync(() => controller.abort()) // `abort` is idempotent.\n)\n})\n```"
      }
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
        "start": {
          "line": 73,
          "column": 14
        },
        "end": {
          "line": 132,
          "column": 2
        }
      },
      {
        "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
        "start": {
          "line": 74,
          "column": 3
        },
        "end": {
          "line": 78,
          "column": 60
        }
      },
      {
        "file": "packages/fx/src/Fx/combinators/onInterrupt.ts",
        "start": {
          "line": 80,
          "column": 3
        },
        "end": {
          "line": 85,
          "column": 28
        }
      }
    ],
    "since": "1.0.0",
    "category": "Resource lifetime"
  }
}
