Last active
December 15, 2015 14:09
-
-
Save lsmith/5271961 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.