Implement `wait` helper method

Allow users to specify an arbitrary JavaScript function as a waiting
condition. This function will be called at an (overridable) interval
until it returns a truthy value. If the function does not return a
truthy value within an (overridable) timeout, throw an error.