diff --git a/src/core/chunked_stream.js b/src/core/chunked_stream.js index 268a2151a..6c0c16db0 100644 --- a/src/core/chunked_stream.js +++ b/src/core/chunked_stream.js @@ -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;