Skip to content

Commit

Permalink
support async function for readFileFn
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphaël Droz committed Jul 30, 2020
1 parent c822748 commit 1858472
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"jasmine-core": "^2.4.1",
"karma": "0.13",
"karma-chrome-launcher": "^1.0.1",
"karma-coverage": "0.5.5",
"karma-coverage": "^2.0.3",
"karma-firefox-launcher": "0.1.7",
"karma-jasmine": "0.3",
"karma-sauce-launcher": "0.3.1",
Expand Down
16 changes: 10 additions & 6 deletions src/flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -1329,31 +1329,31 @@
* Finish preprocess state
* @function
*/
preprocessFinished: function () {
preprocessFinished: async function () {
// Re-compute the endByte after the preprocess function to allow an
// implementer of preprocess to set the fileObj size
this.endByte = this.computeEndByte();

this.preprocessState = 2;
this.send();
await this.send();
},

/**
* Finish read state
* @function
*/
readFinished: function (bytes) {
readFinished: async function (bytes) {
this.readState = 2;
this.bytes = bytes;
this.send();
await this.send();
},


/**
* Uploads the actual data in a POST call
* @function
*/
send: function () {
send: async function () {
var preprocess = this.flowObj.opts.preprocess;
var read = this.flowObj.opts.readFileFn;
if (typeof preprocess === 'function') {
Expand All @@ -1369,7 +1369,11 @@
switch (this.readState) {
case 0:
this.readState = 1;
read(this.fileObj, this.startByte, this.endByte, this.fileObj.file.type, this);
if (read.constructor.name == 'AsyncFunction') {
await read(this.fileObj, this.startByte, this.endByte, this.fileObj.file.type, this);
} else {
read(this.fileObj, this.startByte, this.endByte, this.fileObj.file.type, this);
}
return;
case 1:
return;
Expand Down

0 comments on commit 1858472

Please sign in to comment.