MagicStack / MagicStack/asyncpg

Allow coroutines on add_listener.

Aperta
#546 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
8.1k
Fork
468
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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](https://stackoverflow.com/questions/36076619/test-if-function-or-method-is-normal-or-asynchronous) 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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
postgresql, python
Ambito
api, database
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
32/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.