Horje
constantly send a request until a desired response is recieved expressjs Code Example
constantly send a request until a desired response is recieved expressjs
// your callback gets executed automatically once the data is received
var callback = (data, error) => {
    // consume data
    if (error) {
        console.error(error);
        return;
    }
    console.log(data);
};

// run the request. this function will call itself max. 5 times if the request fails
request(5, callback);

function request(var retries, var callback) {
    axios.post('http://localhost:2000/evaluate', {
        serviceName:"s1"
    }).then(response => {
        // request successful

        if(response.data['done'] == 1) {
            // server done, deliver data to script to consume
            callback(response);
        }
        else {
            // server not done yet
            // retry, if any retries left
            if (retries > 0) {
                request(--retries, callback);
            }
            else {
                // no retries left, calling callback with error
                callback([], "out of retries");
            }
        }
    }).catch(error => {
        // ajax error occurred
        // would be better to not retry on 404, 500 and other unrecoverable HTTP errors
        // retry, if any retries left
        if (retries > 0) {
            request(--retries, callback);
        }
        else {
            // no retries left, calling callback with error
            callback([], error);
        }
    });
}




Javascript

Related
pass body in post request javascript Code Example pass body in post request javascript Code Example
javascript get each element count / occurrences / frequency from a list Code Example javascript get each element count / occurrences / frequency from a list Code Example
rhino js replaceAll Code Example rhino js replaceAll Code Example
Caused by: java.lang.IllegalArgumentException: This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a Caused by: java.lang.IllegalArgumentException: This component requires that you specify a valid TextAppearance attribute. Update your app theme to inherit from Theme.MaterialComponents (or a
map object keys javascript Code Example map object keys javascript Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8