All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lib.xp.examples.task.sleep.js Maven / Gradle / Ivy

var taskLib = require('/lib/xp/task.js');
var assert = require('/lib/xp/testing');

var count = 0;

function fetchRemoteData() {
    count++;
    return count < 2 ? null : [];
}

// BEGIN
var retries = 3;
var result = fetchRemoteData();

while (!result && retries > 0) {
    taskLib.sleep(500); // wait half a second before retrying
    retries--;
    result = fetchRemoteData();
}
// END

assert.assertEquals(2, retries);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy