Edit in JSFiddle

// These are just utility functions for the Fiddle
var log = function (message) {
    if (typeof message == 'array') message = message.join(',');
    $('#log').append(message + ' | ');
};
var _ajax = function(response, callback) {
    $.post(
        '/echo/json',
        {
            json: JSON.stringify(response),
            delay: 10
        },
        callback
    );
};

// Here's the actual code
var _ = window.highland,
    buffering = false,
    i = 0,
    // make a stream of 'click' events for the #add element
    // this simulates the source of events in our application
    source = _('click', $('#add')).map(function (e) {
        // map the events into a incremental number
        // here you would e.g. get the data from one of the parameters and return that instead
        return i += 1;
    }),
    // this function will get called each time a group of 5 elements becomes available.
    consume = function (x) { // x will be an array of elements (usually 5 in this example)
        // simulate an AJAX request where we POST a simple object that contains our array of 5 elements
        _ajax({time:x}, function () {
            if ($('#chk').is(':checked')) {
                // here we simulate a failed consumer call (e.g. failed ajax call)
                log('ERROR'); 
                $('#chk').prop('checked',null);
                // handle the error (e.g. retry after 5 seconds)
                setTimeout(function(){
                    consume(x);
                },5000);
            } else {
                log(x); // consumed successfully
            }
        });
    };

// batch the stream in groups of 5 and start consuming it
source.batch(5).each(consume); // e.g. a function to post AJAX data to server

$('#stop').click(function() {
    source.end();
    log('STOP');
});
<h2>Introduction</h2>

<p>This example demonstrate how Highline can handle a source that's slower than the consumer. It also intends to demonstrate how to handle situations where the consumer fails to execute properly.</p>

<h2>Instructions</h2>

<p>Click on the "Add Data" button to add a single input item to the stream.</p>
<p>You can also click on the "Next batch should fail" check-box to cause a simulation of a failed consumer call (e.g. failed AJAX call). After about 5 seconds you'll see the failed batch execute again. You can appreciate the effect even more if you continue to click on the "Add Data" button during those 5 seconds.</p>
<p>You'll have to click 5 times or more see results, because the stream is consumed in batches of 5 items</p>
<p>
    <a id="add" href="#">Add Data</a>
    <a id="stop" href="#">Stop</a>
    <input type="checkbox" id="chk" />
    <label for="chk">Next batch should fail</label>
</p>

<h4>Output</h4>

<div id="log"></div>
#log {
    font-family: Consolas, 'Courier New', sans-serif;
    
}

External resources loaded into this fiddle: