paranim / pararules

A Nim rules engine
The Unlicense
139 stars 3 forks source link

thenFinally double-fires with empty match second time #8

Closed ul closed 1 year ago

ul commented 1 year ago

This test https://github.com/ul/pararules/blob/thenFinally-double-fire/tests/test4.nim fails with triggerCount was 2 and triggerEmptyCount was 1. Is it a bug or expected behaviour? If it's the latter, would you mind helping me wrap my head around it? Because I'd expect the act rule to be fired only once.

oakes commented 1 year ago

If I am reading this right, it is expected behavior. thenFinally is supposed to fire not only when any match is added or updated, but also if any match is removed. In your test it looks like there is initially one match for the rule, and in the thenFinally you are updating Player, State from Acting to Idle which will cause the match to be removed, which causes thenFinally to run again. thenFinally is mainly meant for creating derived facts and it needs to be able to update the derived fact when one of its values has been removed, like in the AllCharacters example in the readme.

ul commented 1 year ago

That makes sense, thank you! cc @alertpotato