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); |
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
I don't know for certain, since garbage memory leakage and garbage collection isn't my specialty, but I believe it will be fine. When the inner promise resolves, the
getData()
code path will go stale and shouldn't prevent the related promises from being GC'd. Once the exposed promise is not being used, I don't see why it can'be GC'd.But again, it's not my specialty. I really do need to learn more about memory leaks and garbage collection...