Skip to content

Running Synchronous Code as Async Using Lambdas (Code Smell) #162

@BoggerByte

Description

@BoggerByte

Enhancement description

The TodoistAPIAsync class currently wraps synchronous API calls using run_async(lambda: self._api.method(...)). This approach does not truly make the operations asynchronous and introduces inefficiencies, such as blocking the event loop.

To properly support async functionality, the project should consider using httpx, which provides both sync (httpx.Client) and async (httpx.AsyncClient) interfaces. This would allow for a cleaner implementation of async API methods without relying on wrapping sync calls inside lambda functions.

The problem it solves

  • Prevents event loop blocking: The current approach does not truly offload work asynchronously and could degrade performance in async environments.
  • Simplifies the implementation: Removing unnecessary lambda wrappers makes the codebase cleaner and easier to maintain.
  • Provides true async support: Using httpx enables real async HTTP requests without requiring additional workarounds like run_async.

Additional information

  • The httpx library is well-supported and designed for both sync and async HTTP requests.
  • This change would improve compatibility with modern async frameworks while maintaining backward compatibility for sync users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions