Skip to content

Commit 29b0ea6

Browse files
author
ilessiivi
committed
Combine file-added and its filtering into one loop
* Make addFiles call files-added hook with a file list filtered by every individual file-added like in v2 and old synchronous v3 functions * Cleanup: removed the intermediary state objects and array * Cleanup: rename flowfiles array to flowFiles
1 parent b0d603f commit 29b0ea6

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/Flow.js

+11-13
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ export default class Flow extends Eventizer {
536536
* @return Promise{[<FlowFile>,...]} The promise of getting an array of FlowFile.
537537
*/
538538
async addFiles(fileList, event = null, initFileFn = this.opts.initFileFn) {
539-
let item, file, flowfile, uniqueIdentifier, states = [];
539+
let item, file, uniqueIdentifier, flowFiles = [];
540540
const iterator = this.filterFileList(fileList, event);
541541

542542
while ((item = iterator.next()) && !item.done) {
@@ -546,29 +546,27 @@ export default class Flow extends Eventizer {
546546
continue;
547547
}
548548

549-
// ToDo: parallelizable ?
550-
var flowFile = new FlowFile(this, file, uniqueIdentifier),
551-
state = flowFile.bootstrap(event, initFileFn);
552-
states.push(state);
553-
}
549+
let flowFile = new FlowFile(this, file, uniqueIdentifier);
550+
await flowFile.bootstrap(event, initFileFn);
551+
await this.hook('file-added', flowFile, event);
554552

555-
var flowfiles = await Promise.all(states);
556-
for (let ff of flowfiles) {
557-
await this.hook('file-added', ff, event);
553+
if(flowFile && flowFile.file) {
554+
flowFiles.push(flowFile);
555+
}
558556
}
559557

560-
await this.hook('files-added', flowfiles, event);
558+
await this.hook('files-added', flowFiles, event);
561559

562-
flowfiles = flowfiles.filter(e => e && e.file);
563-
for (let file of flowfiles) {
560+
flowFiles = flowFiles.filter(flowFile => flowFile && flowFile.file);
561+
for (let file of flowFiles) {
564562
if (this.opts.singleFile && this.files.length > 0) {
565563
await this.removeFile(this.files[0]);
566564
}
567565
this.files.push(file);
568566
}
569567
await this.hook('files-submitted', this.files, event);
570568

571-
return flowfiles;
569+
return flowFiles;
572570
}
573571

574572
/**

0 commit comments

Comments
 (0)