lib/vmapi.js
function listAllVms(cb) {
        var limit = undefined;
        var offset = params.offset;
        var vms = [];
        var stop = false;

        async.whilst(
            function testAllVmsFetched() {
                return !stop;
            },
            listVms,
            function doneFetching(fetchErr) {
                return cb(fetchErr, vms);
            });

        function listVms(whilstNext) {
            // These options are passed once they are set for the first time
            // or they are passed by the client calling listImages()
            if (offset) {
                params.offset += offset;
            } else {
                params.offset = 0;
            }

            if (limit) {
                params.limit = limit;
            }

            self.get(reqOpts, function (listErr, someVms) {
                if (listErr) {
                    stop = true;
                    return whilstNext(listErr);
                }

                if (!limit) {
                    limit = someVms.length;
                }
                if (!offset) {
                    offset = someVms.length;
                }
                if (someVms.length < limit) {
                    stop = true;
                }

                // We hit this when we either reached an empty page of
                // results or an empty first result
                if (!someVms.length) {
                    stop = true;
                    return whilstNext();
                }

                vms = vms.concat(someVms);
                return whilstNext();
            });
        }
    }
function listAllVms(cb) {
        var limit = undefined;
        var offset = params.offset;
        var vms = [];
        var stop = false;

        async.whilst(
            function testAllVmsFetched() {
                return !stop;
            },
            listVms,
            function doneFetching(fetchErr) {
                return cb(fetchErr, vms);
            });

        function listVms(whilstNext) {
            // These options are passed once they are set for the first time
            // or they are passed by the client calling listImages()
            if (offset) {
                params.offset += offset;
            } else {
                params.offset = 0;
            }

            if (limit) {
                params.limit = limit;
            }

            self.get(reqOpts, function (listErr, someVms) {
                if (listErr) {
                    stop = true;
                    return whilstNext(listErr);
                }

                if (!limit) {
                    limit = someVms.length;
                }
                if (!offset) {
                    offset = someVms.length;
                }
                if (someVms.length < limit) {
                    stop = true;
                }

                // We hit this when we either reached an empty page of
                // results or an empty first result
                if (!someVms.length) {
                    stop = true;
                    return whilstNext();
                }

                vms = vms.concat(someVms);
                return whilstNext();
            });
        }
    }
function listAllVms ( cb ) { var limit = undefined ; var offset = params . offset ; var vms = [ ] ; var stop = false ; async . whilst ( function testAllVmsFetched ( ) { return ! stop ; } , listVms , function doneFetching ( fetchErr ) { return cb ( fetchErr , vms ) ; } ) ; function listVms ( whilstNext ) { // These options are passed once they are set for the first time // or they are passed by the client calling listImages() if ( offset ) { params . offset += offset ; } else { params . offset = 0 ; } if ( limit ) { params . limit = limit ; } self . get ( reqOpts , function ( listErr , someVms ) { if ( listErr ) { stop = true ; return whilstNext ( listErr ) ; } if ( ! limit ) { limit = someVms . length ; } if ( ! offset ) { offset = someVms . length ; } if ( someVms . length < limit ) { stop = true ; } // We hit this when we either reached an empty page of // results or an empty first result if ( ! someVms . length ) { stop = true ; return whilstNext ( ) ; } vms = vms . concat ( someVms ) ; return whilstNext ( ) ; } ) ; } }
This function will execute at least 2 queries when it is not known how the remote VMAPI is returning the collection. If no limit is set, then listVms would receive all VMs on the first call and then perform a second one to discover that all items have been returned. When limit is undefined, listVms will get someVms.length VMs at a time
This function will execute at least 2 queries when it is not known how the remote VMAPI is returning the collection . If no limit is set then listVms would receive all VMs on the first call and then perform a second one to discover that all items have been returned . When limit is undefined listVms will get someVms . length VMs at a time