From 185847232db81320768ea93b02c2ece5dfb976e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Thu, 30 Jul 2020 00:40:29 -0300 Subject: [PATCH] support async function for readFileFn --- package.json | 2 +- src/flow.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 00ae2983..7caf3fcf 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/flow.js b/src/flow.js index 90073301..ee5e858b 100644 --- a/src/flow.js +++ b/src/flow.js @@ -1329,23 +1329,23 @@ * 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(); }, @@ -1353,7 +1353,7 @@ * 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') { @@ -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;