lordmauve / wasabi2d

Cutting-edge 2D game framework for Python
https://wasabi2d.readthedocs.io/
GNU Lesser General Public License v3.0
154 stars 24 forks source link

Allow creating tasks that automatically cancel when a nursery exits #70

Open lordmauve opened 2 years ago

lordmauve commented 2 years ago

When writing Axium it became apparent that service tasks would be extremely helpful.

This is the same idea mentioned in the Trio tracker: https://github.com/python-trio/trio/issues/1521

For Axium these tasks might often be effects that update only as long as the nursery is alive:

async with w2d.Nursery() as ns:
    ns.do(drive_ship(ship))
    ns.run_service(effects.trail(ship))

So if drive_ship() exits the trail is automatically cancelled.