Skip to content

Instantly share code, notes, and snippets.

@palnes palnes/cow.js forked from runeh/cow.js
Last active Aug 29, 2015

Embed
What would you like to do?
"use strict";
var highland = require("highland");
var request = require("request-promise");
var promiseToStream = highland;
var arrayToStream = highland;
var pollerToStream = highland;
function cowPageGenerator(url) {
var page = 1;
return function (push, next) {
console.log("pling", page);
push(null, request(url, { qs: { page: page++ } }));
next();
};
}
function cowStream(url) {
return pollerToStream(cowPageGenerator(url)).flatMap(promiseToStream).map(JSON.parse).map(function (e) {
return e.entries;
}).flatMap(arrayToStream).ratelimit(1, 1000);
}
var url = "http://hotell.difi.no/api/json/mattilsynet/husdyrregisteret/storfeindivider";
cowStream(url).each(console.log);
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.