{
  "id": "@typed/fx/Sink#withStateSemaphore",
  "canonicalId": "@typed/fx/Sink#withStateSemaphore",
  "symbol": {
    "id": "@typed/fx/Sink#withStateSemaphore",
    "packageName": "@typed/fx",
    "moduleName": "Sink",
    "exportName": "withStateSemaphore",
    "kind": "function",
    "signatures": [
      "export declare function withStateSemaphore<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithStateSemaphore<A, E, R, B>, params: {\n    signal: AbortSignal;\n    scheduler: Scheduler;\n}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;"
    ],
    "summary": "Runs a callback with private state whose effectful reads and writes are serialized.",
    "sections": {
      "Why": "Overlapping asynchronous callbacks need a lock to prevent multiple updates from reading the same\nprior state.",
      "Ownership and lifetime": "Each execution owns one mutable cell and one single-permit semaphore. Modify Effects serialize in\nsemaphore-acquisition order, release the permit on completion or interruption, and expose their\ntyped errors and services. Constructing an Effect does not acquire the permit; running it does.\nExit aborts the surrounding callback fiber."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport * as Sink from \"@typed/fx/Sink\"\nconst base = Sink.make(Effect.logError, Effect.log)\nconst program = Sink.withStateSemaphore(base, 0, (state) =>\n  state.updateEffect((n) => Effect.succeed(n + 1)).pipe(Effect.andThen(state.earlyExit)))"
      }
    ],
    "relations": [],
    "source": {
      "file": "packages/fx/src/Sink/combinators.ts",
      "line": 433
    },
    "since": "1.0.0",
    "category": "Stateful delivery"
  },
  "exposure": {
    "recordKind": "declaration",
    "id": "@typed/fx/Sink#withStateSemaphore",
    "packageName": "@typed/fx",
    "packageVersion": "2.0.0-beta.13",
    "moduleName": "Sink",
    "consumerSpecifier": "@typed/fx/Sink",
    "exportName": "withStateSemaphore",
    "qualifiedName": "withStateSemaphore",
    "declarationKey": "declaration:bdc87fd99c01cee5624b26e9",
    "family": "function",
    "signatures": [
      "export declare function withStateSemaphore<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithStateSemaphore<A, E, R, B>, params: {\n    signal: AbortSignal;\n    scheduler: Scheduler;\n}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;"
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Sink/combinators.ts",
        "start": {
          "line": 433,
          "column": 1
        },
        "end": {
          "line": 459,
          "column": 2
        }
      }
    ],
    "aliases": [
      "@typed/fx#Sink.withStateSemaphore"
    ],
    "isAlias": false,
    "static": false
  },
  "declaration": {
    "declarationKey": "declaration:bdc87fd99c01cee5624b26e9",
    "name": "withStateSemaphore",
    "family": "function",
    "facets": [
      {
        "family": "function",
        "syntaxKind": "FunctionDeclaration",
        "signatures": [
          "export declare function withStateSemaphore<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithStateSemaphore<A, E, R, B>, params: {\n    signal: AbortSignal;\n    scheduler: Scheduler;\n}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;"
        ],
        "typeParameters": [
          "A",
          "E",
          "R",
          "B",
          "R2"
        ],
        "sourceSpans": [
          {
            "file": "packages/fx/src/Sink/combinators.ts",
            "start": {
              "line": 433,
              "column": 1
            },
            "end": {
              "line": 459,
              "column": 2
            }
          }
        ],
        "static": false,
        "readonly": false,
        "optional": false
      }
    ],
    "signatures": [
      "export declare function withStateSemaphore<A, E, R, B, R2>(sink: Sink<A, E, R>, state: B, f: (sink: Sink.WithStateSemaphore<A, E, R, B>, params: {\n    signal: AbortSignal;\n    scheduler: Scheduler;\n}) => Effect.Effect<unknown, never, R2>): Effect.Effect<void, never, R | R2>;"
    ],
    "typeParameters": [
      "A",
      "E",
      "R",
      "B",
      "R2"
    ],
    "summary": "Runs a callback with private state whose effectful reads and writes are serialized.",
    "sections": {
      "Why": "Overlapping asynchronous callbacks need a lock to prevent multiple updates from reading the same\nprior state.",
      "Ownership and lifetime": "Each execution owns one mutable cell and one single-permit semaphore. Modify Effects serialize in\nsemaphore-acquisition order, release the permit on completion or interruption, and expose their\ntyped errors and services. Constructing an Effect does not acquire the permit; running it does.\nExit aborts the surrounding callback fiber."
    },
    "examples": [
      {
        "language": "ts",
        "code": "import { Effect } from \"effect\"\nimport * as Sink from \"@typed/fx/Sink\"\nconst base = Sink.make(Effect.logError, Effect.log)\nconst program = Sink.withStateSemaphore(base, 0, (state) =>\n  state.updateEffect((n) => Effect.succeed(n + 1)).pipe(Effect.andThen(state.earlyExit)))"
      }
    ],
    "sourceSpans": [
      {
        "file": "packages/fx/src/Sink/combinators.ts",
        "start": {
          "line": 433,
          "column": 1
        },
        "end": {
          "line": 459,
          "column": 2
        }
      }
    ],
    "since": "1.0.0",
    "category": "Stateful delivery"
  }
}
