Skip to content

Commit

Permalink
Use pqueue to run only one promise
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas Hirt committed Oct 10, 2019
1 parent d1b7867 commit 8dbadff
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/files/src/mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import moment from 'moment'
import FileUpload from './FileUpload.js'
import fileTypeIconMappings from './fileTypeIconMappings.json'
import { mapActions, mapGetters } from 'vuex'
const { default: PQueue } = require('p-queue')

export default {
filters: {
Expand All @@ -27,7 +28,8 @@ export default {
changeFileName: false,
fileToBeDeleted: '',
newName: '',
originalName: null
originalName: null,
queue: new PQueue({ concurrency: 1 })
}),
computed: {
...mapGetters('Files', ['searchTerm', 'inProgress', 'files', 'selectedFiles', 'highlightedFile', 'activeFiles']),
Expand Down Expand Up @@ -328,11 +330,15 @@ export default {
const createFolderPromises = []
const rootDir = directoriesToCreate[0]
for (const directory of directoriesToCreate) {
let p

if (this.publicPage()) {
createFolderPromises.push(this.$client.publicFiles.createFolder(this.rootPath + directory))
p = this.queue.add(() => this.$client.publicFiles.createFolder(this.rootPath + directory))
} else {
createFolderPromises.push(this.$client.files.createFolder(this.rootPath + directory))
p = this.queue.add(() => this.$client.files.createFolder(this.rootPath + directory))
}

createFolderPromises.push(p)
}
// Upload files
const uploadPromises = []
Expand Down

0 comments on commit 8dbadff

Please sign in to comment.