Skip to content

Instantly share code, notes, and snippets.

@jweisman jweisman/parallel.js
Last active Jan 16, 2019

What would you like to do?
Ex Libris Alma - Parallel API Calls
const { PerformanceObserver, performance } = require('perf_hooks');
const alma = require('almarestapi-lib');
const records = 10000;
const limit = 25;
const url = '/users?view=brief';
const arrayName = 'user';
var offset = 0, total = 0, processed = 0;
async function main() {
do {
var data = await alma.getp(url+`&limit=${limit}&offset=${offset}`);
total = data.total_record_count;
var i=0, e=0;
var t1 =;
var actions = data[arrayName].map(async item => {
if (
return alma.getp('?&view=brief').then(data => i++).catch(err => e++);
await Promise.all(actions);
offset += actions.length;
processed += actions.length;
var t2 =;
console.log([processed, i, e, t2-t1].join(','));
if (offset >= total) offset = 0; // loop multiple times if necessary
} while (processed < records);

This comment has been minimized.

Copy link
Owner Author

jweisman commented Dec 4, 2018

After downloading the parallel.js file, install the Alma Node library:

npm i almarestapi-lib

To run add your API key to the environment, or on the command line:

ALMA_API_KEY=l7xxxxxxxxxxxxx node parallel.js 2> error.txt 1> output.txt

The output can be opened in Excel to create a graph.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.