Expectations can now execute asynchronous actions

Recently we introduced waiting through a mechanism of expectations. This pull requests introduces additional features to expectations, and that is "actions" - pieces of code that will be asynchronously executed after the expectation has been fulfilled.

This pull request also fixes some long standing and well-hidden threading problems, making some changes to the tests in the process.