Class (GI Class)

Dex-1DexLimiterSince 1.2

Dex.Limiter limits the number of operations running concurrently.

A limiter starts with a fixed number of permits. Use Dex.Limiter.acquire and Dex.Limiter.release directly when a permit must cover a custom scope, or use Dex.Limiter.run or Dex.Limiter.run_on_pool to acquire a permit and release it automatically when the work completes.

1.2

Hierarchy (View Summary)

Index
$gtype: GType<Dex.Limiter>
  • Acquires one permit from limiter.

    The returned future resolves to true when a permit has been acquired. Call Dex.Limiter.release exactly once for each resolved acquisition.

    If the returned future is discarded before the permit is acquired, the permit is returned to the limiter when it becomes available. If limiter is closed before acquisition completes, the returned future rejects with Dex.Error.SEMAPHORE_CLOSED.

    Returns Dex.Future

    a future that resolves when a permit is acquired

    1.2

  • Closes limiter.

    Pending and future acquisitions reject with Dex.Error.SEMAPHORE_CLOSED. Permits already acquired remain valid, but releasing them after close will not make them available for new work.

    Returns void

    1.2

  • Closes limiter and waits for all queued and running work to complete.

    After this function is called, new acquire attempts are rejected with Dex.Error.SEMAPHORE_CLOSED.

    The returned future resolves to true once all outstanding pending acquire futures and held permits are complete. Existing permit holders must still eventually release.

    Returns Dex.Future

    a Dex.Future that resolves to true

    1.2

  • Gets the maximum number of permits available from limiter.

    Returns number

    the maximum number of concurrent operations

    1.2

  • Runs func while holding one permit from limiter.

    The returned future resolves or rejects with the result of the spawned fiber. The permit is released automatically after the fiber resolves or rejects. If the returned future is discarded after the fiber starts, the fiber is allowed to complete so that the permit can be released.

    Parameters

    • scheduler: Dex.Scheduler

      scheduler to spawn func on, or null for the thread default

    • stack_size: number | bigint

      stack size for the spawned fiber, or zero to use the default

    • func: FiberFunc

      fiber function to run after a permit is acquired

    Returns Dex.Future

    a future representing the spawned fiber

    1.2

  • Runs func while holding one permit from limiter.

    The returned future resolves or rejects with the result of the spawned coroutine. The permit is released automatically after the coroutine resolves or rejects. If the returned future is discarded after the coroutine starts, the coroutine is allowed to complete so that the permit can be released.

    Parameters

    • scheduler: Dex.Scheduler

      scheduler to spawn func on, or null for the thread default

    • func: CoroutineFunc

      coroutine function to run after a permit is acquired

    Returns Dex.Future

    a future representing the spawned coroutine

    1.2

  • Runs thread_func on pool while holding one permit from limiter.

    The returned future resolves or rejects with the result of the submitted thread-pool work. The permit is released automatically after the work resolves or rejects. If the returned future is discarded after the work is submitted to pool, the work is allowed to complete so that the permit can be released.

    Workers in Dex.ThreadPool are not scheduler threads, so thread_func must not use dex_await().

    Parameters

    Returns Dex.Future

    a future representing the submitted work

    1.2

  • Releases a reference on the given object, and decreases its reference count by one.

    If it was the last reference, the resources associated to the instance are freed.

    Returns void

Interfaces

SignalSignatures