Skip to content

Instantly share code, notes, and snippets.

@runeh
Created December 8, 2014 08:37
Show Gist options
  • Save runeh/4711f14fb4816cb89baf to your computer and use it in GitHub Desktop.
Save runeh/4711f14fb4816cb89baf to your computer and use it in GitHub Desktop.
var fs = require("fs");
var Bacon = require("baconjs");
var lifestyle = require("lifestyle");
var root = "https://api.finn.no/iad/"
var adListPath = "adids.txt";
var client = new lifestyle.FinnClient(root);
function fetchAd(id) {
return Bacon.fromPromise(client.getAd(id));
}
function handleError(err) {
process.stderr.write(err.message + "\n");
}
function handleSuccess(ad) {
process.stdout.write(JSON.stringify(ad) + "\n");
}
function getAdIds(path) {
return fs.readFileSync(path, 'utf8').trim().split('\n');
}
var responses = Bacon
.fromArray(getAdIds(adListPath))
.flatMapWithConcurrencyLimit(6, fetchAd);
responses.onValue(handleSuccess);
responses.onError(handleError);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment