Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.