Skip to content

Instantly share code, notes, and snippets.

@lsmith
Last active December 15, 2015 14:09
Show Gist options
  • Save lsmith/5271961 to your computer and use it in GitHub Desktop.
Save lsmith/5271961 to your computer and use it in GitHub Desktop.
var dataPromise = new Y.Promise(function (resolve, reject) {
var data = [];
function getData(offset) {
return new Y.Promise(function (dataResolve, dataReject) {
Y.io('getdata.php?offset=' + offset, {
on: {
success: function (id, response) {
var dataset = Y.JSON.parse(response.responseText);
data.push.apply(data, dataset);
dataResolve((dataset.length < 100) ? data : getData(offset + 100));
},
failure: function () {
dataReject(new Error("Oh noes!"));
}
}
});
});
}
getData(0).then(resolve, reject);
});
dataPromise.then(function (allTheData) {
// allTheData has ... all of the data
}, handleError);
@ItsAsbreuk
Copy link

I thought you knew everything ;)

You may be right.
On irc we discussed this as well and all say no memoryleaks to be expected.
I think I messed up: the promise may hold options, but GC issues would be expected the other way arround (when an external object were to hold the promise). At least, I think so...

Thx.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment