Merge pull request #4667 from Snuffleupagus/remove-LegacyPromise-chunked_stream.js

Remove LegacyPromise in src/core/chunked_stream.js
This commit is contained in:
Tim van der Meij 2014-05-01 21:02:43 +02:00
commit 4224bae810

View File

@ -15,7 +15,7 @@
* limitations under the License.
*/
/* globals assert, MissingDataException, isInt, NetworkManager, Promise,
isEmptyObj, LegacyPromise */
isEmptyObj, createPromiseCapability */
'use strict';
@ -278,7 +278,8 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
this.requestsByChunk = {};
this.callbacksByRequest = {};
this.loadedStream = new LegacyPromise();
this._loadedStreamCapability = createPromiseCapability();
if (args.initialData) {
this.setInitialData(args.initialData);
}
@ -289,7 +290,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
setInitialData: function ChunkedStreamManager_setInitialData(data) {
this.stream.onReceiveInitialData(data);
if (this.stream.allChunksLoaded()) {
this.loadedStream.resolve(this.stream);
this._loadedStreamCapability.resolve(this.stream);
} else if (this.msgHandler) {
this.msgHandler.send('DocProgress', {
loaded: data.length,
@ -299,7 +300,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
},
onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
return this.loadedStream;
return this._loadedStreamCapability.promise;
},
// Get all the chunks that are not yet loaded and groups them into
@ -307,7 +308,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
var missingChunks = this.stream.getMissingChunks();
this.requestChunks(missingChunks);
return this.loadedStream;
return this._loadedStreamCapability.promise;
},
requestChunks: function ChunkedStreamManager_requestChunks(chunks,
@ -443,7 +444,7 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
this.stream.onReceiveData(begin, chunk);
if (this.stream.allChunksLoaded()) {
this.loadedStream.resolve(this.stream);
this._loadedStreamCapability.resolve(this.stream);
}
var loadedRequests = [];
@ -503,6 +504,10 @@ var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
});
},
onError: function ChunkedStreamManager_onError(err) {
this._loadedStreamCapability.reject(err);
},
getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
var chunk = Math.floor(begin / this.chunkSize);
return chunk;