Module

_internal.invoke

Invoke helpers — call sync or async handlers uniformly.

Chirp handlers can bedef or async def. Any code that calls a user-provided handler must handle both cases. This module provides a single helper so the sync/async check lives in exactly one place.

Sync handlers run inasyncio.to_threadto avoid blocking the event loop (critical for CPU-bound work and free-threading scaling).

Usage::

from chirp._internal.invoke import invoke

result = await invoke(handler, *args, **kwargs)

Functions

invoke 5 Any
Call a handler and await the result if it's a coroutine. When *is_async* is pr…
async
async def invoke(handler: Any, *args: Any, is_async: bool | None = None, inline_sync: bool = False, **kwargs: Any) -> Any

Call a handler and await the result if it's a coroutine.

When is_async is provided (from a compiled InvokePlan), the per-request inspect.iscoroutinefunctioncall is skipped entirely.

When inline_sync is True and the handler is synchronous, it runs on the event loop thread instead ofasyncio.to_thread— useful for lightweight handlers where the thread-dispatch overhead exceeds the work itself.

Parameters
Name Type Description
handler Any
*args Any
is_async bool | None Default:None
inline_sync bool Default:False
**kwargs Any
Returns
Any