Open x0139 opened 6 years ago
OK, this is up to discuss. Unfortunately, implementation could be tricky because signals are designed to be sync and we need async. And also if someone added sync signals they won't be called from async code. This could be even worse than having no support for signals at all.
However, we could try calling sync signals with run_in_executor()
.
There is small problem to call run_in_executor()
- await objects.create() uses insert, and in playhouse peewee said:
Peewee signals do not work when you use the Model.insert(), Model.update(), or Model.delete()
Why signals with async is a bad idea?
I'm not saying this is a bad idea. I just point that it may cause unexpected behaviour and need to be designed properly. Consider someone has added signals in their sync codebase. Should we trigger those signals or not? If we do that, than we have to use run_in_executor()
. And yes, we should replicate the logic from sync version as close as possible.
Please add Signal playhouse support on insert method to work with await objects.create()