Test and fix for "infinite" WaitPool growth

If an app coordinated actions with wait(unique_token) calls, every
unique_token would exist in the internal WaitPool for the lifetime of
the app.

This change makes sure to clean up the tokens and related empty sets
when then are no longer needed.
Some docstrings for a few core API functions