pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.49k stars 525 forks source link

asyncio: Fix setting AsyncTimeout._on_timeout trigger, when timeout=0 #579

Closed Rysbai closed 1 year ago

Rysbai commented 1 year ago

Bug description

I wanted to initialise AsyncTimeout state with timeout=0, so I can set timeout after initialisation before/after entering state. But trigger is not called after setting timeout > 0, entering the state and timeout has passed.

So in my project, I set on_timeout along with the timeout before entering to state and it's working.

Root cause analyse result

AsyncTimeout._on_timeout is a list of triggers and there is a on_timeout setter that listifies value before setting. AsyncTimeout.__init__ uses setter if timeout > 0, but it passes directly if timeout = 0.

aleneum commented 1 year ago

I can confirm this issue arises when on_timeout is not a list. When setting _on_timeout directly the parameter is not listified. Setting on_timeout instead, solves this issue.

Thank you @Rysbai