-
-
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); |
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...
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.
Luke, suppose I create the next Promise.
Will there be a memoryleak? It seem to me that there is a closure (options-object) that could prevent every created 'getData' from being freed from memory.
Am I right? Or isn't it?
Marco.