Created
December 8, 2014 08:37
-
-
Save runeh/4711f14fb4816cb89baf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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