MagicStack / MagicStack/asyncpg

Allow coroutines on add_listener.

Open
#546 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
8.1k
Forks
468
PR merge metrics
No merged PRs in 30d

Description

The current code that process a notification uses the method call_soon which expects a callable, why not to use create_task (or ensure_future for compatibility reasons) after checking if the callback is a coroutine?

There are different ways to do this, either just checking if the callback is a coroutine as described in here for example. Another way is just to add an extra argument or a different method to register coroutines.

Would it make sense to add a context? I am currently passing extra arguments to the callback via functools.partial.

Let me know if something like this would be accepted I can create a PR with the implementation.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the add_listener entry point and the notification processing that currently calls call_soon. Compare create_task and ensure_future for coroutine callbacks, including the existing functools.partial usage for extra arguments. Done should include an agreed callback API and compatibility behavior, with tests covering regular and coroutine listeners.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
api, database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.