features/extra/helpers.js
function eventually(callback, block, options) {

    if (!options) options = {};
    if (!options.delay) options.delay = 0;
    if (!options.backoff) options.backoff = 500;
    if (!options.maxTime) options.maxTime = 5;

    var delay = options.delay;
    var started = this.AWS.util.date.getDate();

    var self = this;
    var retry = function() { callback(); };
    retry.fail = function(err) {
      var now = self.AWS.util.date.getDate();
      if (now - started < options.maxTime * 1000) {
        setTimeout(function () {
          delay += options.backoff;
          block.call(self, retry);
        }, delay);
      } else {
        callback.fail(err || new Error('Eventually block timed out'));
      }
    };

    block.call(this, retry);

  }
function eventually(callback, block, options) {

    if (!options) options = {};
    if (!options.delay) options.delay = 0;
    if (!options.backoff) options.backoff = 500;
    if (!options.maxTime) options.maxTime = 5;

    var delay = options.delay;
    var started = this.AWS.util.date.getDate();

    var self = this;
    var retry = function() { callback(); };
    retry.fail = function(err) {
      var now = self.AWS.util.date.getDate();
      if (now - started < options.maxTime * 1000) {
        setTimeout(function () {
          delay += options.backoff;
          block.call(self, retry);
        }, delay);
      } else {
        callback.fail(err || new Error('Eventually block timed out'));
      }
    };

    block.call(this, retry);

  }
function eventually ( callback , block , options ) { if ( ! options ) options = { } ; if ( ! options . delay ) options . delay = 0 ; if ( ! options . backoff ) options . backoff = 500 ; if ( ! options . maxTime ) options . maxTime = 5 ; var delay = options . delay ; var started = this . AWS . util . date . getDate ( ) ; var self = this ; var retry = function ( ) { callback ( ) ; } ; retry . fail = function ( err ) { var now = self . AWS . util . date . getDate ( ) ; if ( now - started < options . maxTime * 1000 ) { setTimeout ( function ( ) { delay += options . backoff ; block . call ( self , retry ) ; } , delay ) ; } else { callback . fail ( err || new Error ( 'Eventually block timed out' ) ) ; } } ; block . call ( this , retry ) ; }
Call this function with a block that will be executed multiple times
to deal with eventually consistent conditions.

this.When(/^I something is eventually consistent$/, function(callback) {
this.eventually(callback, function(next) {
doSomething(function(response) {
if (response != notWhatIExpect) {
next.fail();
} else {
next();
}
});
});
});

You can pass in a few options after the function:

delay: The number of milliseconds to delay before retrying.
backoff: Add this number of milliseconds to the delay between each attempt.
maxTime: Maximum duration of milliseconds to wait for success.
Call this function with a block that will be executed multiple times to deal with eventually consistent conditions .