Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove LegacyPromise in src/core/chunked_stream.js #4667

Merged
merged 2 commits into from
May 1, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/core/chunked_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/
/* globals assert, MissingDataException, isInt, NetworkManager, Promise,
isEmptyObj, LegacyPromise */
isEmptyObj, createPromiseCapability */

'use strict';

Expand Down Expand Up @@ -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);
}
Expand All @@ -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,
Expand All @@ -299,15 +300,15 @@ 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
// contiguous ranges to load in as few requests as possible
requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
var missingChunks = this.stream.getMissingChunks();
this.requestChunks(missingChunks);
return this.loadedStream;
return this._loadedStreamCapability.promise;
},

requestChunks: function ChunkedStreamManager_requestChunks(chunks,
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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;
Expand Down