Skip to content

Commit c698739

Browse files
authored
Merge pull request #37 from yllieth/add-throttling_on_upload_progress_handlers
add throttling on upload progress handlers
2 parents 48aa447 + 992b67c commit c698739

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "predicsis_ml_sdk-javascript",
3-
"version": "0.7.4",
3+
"version": "0.7.5",
44
"authors": [
55
"Yllieth <[email protected]>",
66
"Dehau"

dist/predicsis-jsSDK.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,26 +3584,31 @@ angular
35843584
var uploadPath = ctx.path;
35853585
var container = ctx.container;
35863586
var type = ctx.type;
3587+
3588+
var progressHandler = _.throttle(function(ctx) {
3589+
chunksProgress[ctx.index] = ctx.progress.loaded;
3590+
var progression = chunksProgress.reduce(function(m, v) { return m + v; }, 0) / file.size;
3591+
events.emit('progress', progression * 100);
3592+
}, 100);
3593+
35873594
var uploadChunksEvents = new EventEmitter();
35883595
uploadChunksEvents.on('start', function(ctx) {
35893596
chunksProgress[ctx.index] = 0;
35903597
if (ctx.cancel) {
35913598
chunksCancel[ctx.index] = function() { ctx.cancel(); };
35923599
}
3593-
uploadChunksEvents.on('progress', function(ctx) {
3594-
chunksProgress[ctx.index] = ctx.progress.loaded;
3595-
var progression = chunksProgress.reduce(function(m, v) { return m + v; }, 0) / file.size;
3596-
events.emit('progress', progression * 100);
3597-
});
3600+
uploadChunksEvents.on('progress', progressHandler);
35983601
});
35993602
uploadChunksEvents.on('end', function() { fileOffset += chunkSize;});
36003603
uploadChunksEvents.on('end', function(ctx) { delete chunksCancel[ctx.index]; });
3604+
36013605
var result = Promise
36023606
.map(
36033607
chunks(file, { chunkSize: chunkSize, fileOffset: fileOffset }),
36043608
function(v) { return uploadChunk(v.chunk, v.index, uploadId, uploadPath, uploadChunksEvents); },
36053609
{ concurrency : 3 }
36063610
);
3611+
36073612
return result
36083613
.then(function() { return { uploadId: uploadId, uploadPath: uploadPath, container: container, type: type }; });
36093614
})

dist/predicsis-jsSDK.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/predicsis-jsSDK.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/helper/uploadHelper.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,26 +145,31 @@ angular
145145
var uploadPath = ctx.path;
146146
var container = ctx.container;
147147
var type = ctx.type;
148+
149+
var progressHandler = _.throttle(function(ctx) {
150+
chunksProgress[ctx.index] = ctx.progress.loaded;
151+
var progression = chunksProgress.reduce(function(m, v) { return m + v; }, 0) / file.size;
152+
events.emit('progress', progression * 100);
153+
}, 100);
154+
148155
var uploadChunksEvents = new EventEmitter();
149156
uploadChunksEvents.on('start', function(ctx) {
150157
chunksProgress[ctx.index] = 0;
151158
if (ctx.cancel) {
152159
chunksCancel[ctx.index] = function() { ctx.cancel(); };
153160
}
154-
uploadChunksEvents.on('progress', function(ctx) {
155-
chunksProgress[ctx.index] = ctx.progress.loaded;
156-
var progression = chunksProgress.reduce(function(m, v) { return m + v; }, 0) / file.size;
157-
events.emit('progress', progression * 100);
158-
});
161+
uploadChunksEvents.on('progress', progressHandler);
159162
});
160163
uploadChunksEvents.on('end', function() { fileOffset += chunkSize;});
161164
uploadChunksEvents.on('end', function(ctx) { delete chunksCancel[ctx.index]; });
165+
162166
var result = Promise
163167
.map(
164168
chunks(file, { chunkSize: chunkSize, fileOffset: fileOffset }),
165169
function(v) { return uploadChunk(v.chunk, v.index, uploadId, uploadPath, uploadChunksEvents); },
166170
{ concurrency : 3 }
167171
);
172+
168173
return result
169174
.then(function() { return { uploadId: uploadId, uploadPath: uploadPath, container: container, type: type }; });
170175
})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "predicsis_ml_sdk-javascript",
3-
"version": "0.7.4",
3+
"version": "0.7.5",
44
"description": "Javascript SDK for PredicSis ML API",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)