1@listen(or_(review_contract, check_invoice, hand_to_person))2defwrite_report(self, result):3return"report: "+ result
Terminal
1(env)$ python demo.py
Output
report: reviewed the contractreport: checked the invoicereport: handed it to a person
Every document got a report from the same step, and result held whatever its own path returned. The router lets only one path run, so exactly one of the three ever finishes:
or_() doesn't wait for a second step. Let's make the report wait for the start and for the review, which both finish for a contract. It prints, so we see each time it runs. Change write_report in demo.py:
Run it for the contract only. Change documents in demo.py:
Python
1documents =["contract"]
Terminal
1(env)$ python demo.py
Output
report: read the contractreviewed the contract
write_report ran once, for read_document, the first to finish. When review_contract finished, no second report came, and kickoff() gave back the review, the last step's result:
Drawing diagram…
InputToolor_() runs once, for the first step to finish
Let's remove the program. The folder stays for the next chapter.