Add WaitScope::poll() and Promise::poll() to pump all events.
These are useful in unit tests. Often, some tasks have been queued, and we want to test that a particular thing happens or doesn't happen as a result of those tasks, without actually waiting on any specific promise. We need a way to run the event queue until it is empty. For that, we add WaitScope::poll(). Or, sometimes, we want to check if a specific promise is (or is not!) resolved as a result of the tasks that have been queued so far, but we may not want to actulaly wait() on it for a couple reasons: - We may actually want to verify that the promise is *not* resolved by tasks so far. wait()ing on it would be expected to deadlock. - We may expect the promise to resolve, but would prefer not to deadlock if it doesn't resolve (we'd rather fail fast). For this, we add Promise::poll(). There are lots of tests I've written which could be simplified by this, but for now I'm not refactoring any existing tests. Note that adding these (particularly Promise::poll()) required updating the async framework a bit, in that this is the first case where PromiseNode::onReady() might be called multiple times, or might be canceled without destroying the PromiseNode entirely. Luckily this was not hard to account for. (We still have the rule that get() can only be called once, though.)
Showing
Please
register
or
sign in
to comment