Wait until condition is met Selenium-Webdriver
<p>I am trying to create additional conditions on top of the selenium-webdriver conditions. I am still trying to grasp the complete concept of promises and callbacks. I have drastically improved thanks to the help of stack overflow. I am unsure of how to repeat a condition every so many seconds in javascript. My inheritance may be wrong as well.</p>

<pre><code>var WebElementCondition = require('./selenium-webdriver/lib/until');

var ExpectedConditions = function()
{
    this.waitForWindowWithTitle = function (title)
    {

        return driver.getAllWindowHandles().then(function (title, handles) {

            console.log(handles.length + ' .then function');

            for (var window in handles) {
                if (window.title === title) 
                {
                    return true;
                }
                else 
                {
                    return false;
                }
            }
        });

    }
}

module.exports = ExpectedConditions;
require('util').inherits(module.exports, WebElementCondition);
</code></pre>

<p>In waitForWindowWithTitle function would I do something like </p>

<pre><code>return driver.wait(10000).then(function() {
     driver.getAllWindowHandles().then(function (title, handles) {

        console.log(handles.length + ' .then function');

        for (var window in handles) {
            if (window.title === title)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    });
});
</code></pre>