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