Add a util::Task class to manage async operations.
Add cancellation support to util::Task.
Add memory management to util::Task.
Fix a race condition in the master election.

It was only when stopping the election, so not too major, but still, let's
fix it!