Hyperlinkv0.8.0-beta.28

TxSemaphore

TxSemaphore.isTxSemaphoreconsteffect/TxSemaphore.ts:707
(u: unknown): u is TxSemaphore

Determines if the provided value is a TxSemaphore.

When to use

Use to narrow an unknown value before treating it as a TxSemaphore.

Example (Checking semaphore values)

import { Effect, TxSemaphore } from "effect"

const program = Effect.gen(function*() {
  const semaphore = yield* TxSemaphore.make(5)
  const notSemaphore = { some: "object" }

  console.log(TxSemaphore.isTxSemaphore(semaphore)) // true
  console.log(TxSemaphore.isTxSemaphore(notSemaphore)) // false

  // Useful for runtime type checking in generic functions
  if (TxSemaphore.isTxSemaphore(semaphore)) {
    const available = yield* TxSemaphore.available(semaphore)
    console.log(`Available permits: ${available}`)
  }
})
guardsmake
export const isTxSemaphore = (u: unknown): u is TxSemaphore => hasProperty(u, TypeId)