Home / Function/ aacquire() — langchain Function Reference

aacquire() — langchain Function Reference

Architecture documentation for the aacquire() function in rate_limiters.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  022b3bdb_ff2e_b5b9_09ea_d248b2fd2811["aacquire()"]
  29cf4437_3b06_c93f_9779_9154d2ed9ff9["InMemoryRateLimiter"]
  022b3bdb_ff2e_b5b9_09ea_d248b2fd2811 -->|defined in| 29cf4437_3b06_c93f_9779_9154d2ed9ff9
  21372498_63f5_8ec9_0d35_6d26093dd7ed["aacquire()"]
  21372498_63f5_8ec9_0d35_6d26093dd7ed -->|calls| 022b3bdb_ff2e_b5b9_09ea_d248b2fd2811
  e0964492_c52e_ec68_41ea_efa229196967["_consume()"]
  022b3bdb_ff2e_b5b9_09ea_d248b2fd2811 -->|calls| e0964492_c52e_ec68_41ea_efa229196967
  21372498_63f5_8ec9_0d35_6d26093dd7ed["aacquire()"]
  022b3bdb_ff2e_b5b9_09ea_d248b2fd2811 -->|calls| 21372498_63f5_8ec9_0d35_6d26093dd7ed
  style 022b3bdb_ff2e_b5b9_09ea_d248b2fd2811 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/rate_limiters.py lines 222–250

    async def aacquire(self, *, blocking: bool = True) -> bool:
        """Attempt to acquire a token from the rate limiter. Async version.

        This method blocks until the required tokens are available if `blocking`
        is set to `True`.

        If `blocking` is set to `False`, the method will immediately return the result
        of the attempt to acquire the tokens.

        Args:
            blocking: If `True`, the method will block until the tokens are available.
                If `False`, the method will return immediately with the result of
                the attempt.

        Returns:
            `True` if the tokens were successfully acquired, `False` otherwise.
        """
        if not blocking:
            return self._consume()

        while not self._consume():  # noqa: ASYNC110
            # This code ignores the ASYNC110 warning which is a false positive in this
            # case.
            # There is no external actor that can mark that the Event is done
            # since the tokens are managed by the rate limiter itself.
            # It needs to wake up to re-fill the tokens.
            # https://docs.astral.sh/ruff/rules/async-busy-wait/
            await asyncio.sleep(self.check_every_n_seconds)
        return True

Domain

Subdomains

Called By

Frequently Asked Questions

What does aacquire() do?
aacquire() is a function in the langchain codebase, defined in libs/core/langchain_core/rate_limiters.py.
Where is aacquire() defined?
aacquire() is defined in libs/core/langchain_core/rate_limiters.py at line 222.
What does aacquire() call?
aacquire() calls 2 function(s): _consume, aacquire.
What calls aacquire()?
aacquire() is called by 1 function(s): aacquire.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free