Last active
August 29, 2015 14:16
-
-
Save amykyta/a764a03c3d08362799c2 to your computer and use it in GitHub Desktop.
What's a nicer way to do this? Without having that all_data array around?
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 qhttp = require('q-io/http'); | |
var _ = require('lodash'); | |
var some_url = "http://localhost:8080/getsome/" | |
var makeNextUrl = _.bind(String.prototype.concat, some_url); | |
var all_data = []; | |
function getData(resp){ | |
resp = JSON.parse(resp); | |
if(resp.nextLink){ | |
all_data.push(resp.data) | |
return qhttp.read(makeNextUrl(resp.nextLink)) | |
.then(getData); | |
} else { | |
return all_data.concat(resp.data).join(''); | |
} | |
} | |
qhttp.read(makeNextUrl('0')) | |
.then(getData) | |
.then(console.log) | |
.done() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would do this recursively. Recursion + async is a tasty combo.
I haven't run this, but consider something like this: