chore(xo-server): remove promise-toolbox/all uses (#5685)

This commit is contained in:
Julien Fontanet
2021-03-22 15:58:13 +01:00
committed by GitHub
parent b4787bf444
commit a968c2d2b7
4 changed files with 13 additions and 7 deletions

View File

@@ -0,0 +1,6 @@
import zipObject from 'lodash/zipObject'
export const asyncMapValues = async (object, iteratee) => {
const keys = Object.keys(object)
return zipObject(keys, await Promise.all(keys.map(key => iteratee(object[key], key, object))))
}

View File

@@ -159,7 +159,7 @@ export const noop = () => {}
// -------------------------------------------------------------------
export { pAll, pDelay, pFinally, pFromCallback, pReflect, promisify, promisifyAll } from 'promise-toolbox'
export { pDelay, pFinally, pFromCallback, pReflect, promisify, promisifyAll } from 'promise-toolbox'
// -------------------------------------------------------------------

View File

@@ -24,7 +24,8 @@ import { satisfies as versionSatisfies } from 'semver'
import createSizeStream from '../size-stream'
import ensureArray from '../_ensureArray'
import fatfsBuffer, { init as fatfsBufferInit } from '../fatfs-buffer'
import { camelToSnakeCase, forEach, map, pAll, parseSize, pDelay, pFinally, promisifyAll } from '../utils'
import { asyncMapValues } from '../_asyncMapValues'
import { camelToSnakeCase, forEach, map, parseSize, pDelay, pFinally, promisifyAll } from '../utils'
import mixins from './mixins'
import OTHER_CONFIG_TEMPLATE from './other-config-template'
@@ -894,7 +895,7 @@ export default class Xapi extends XapiBase {
//
// TODO: move all VDIs creation before the VM and simplify the code
const vbds = groupBy(delta.vbds, 'VDI')
const newVdis = await map(delta.vdis, async (vdi, vdiRef) => {
const newVdis = await asyncMapValues(delta.vdis, async (vdi, vdiRef) => {
let newVdi
const remoteBaseVdiUuid = detectBase && vdi.other_config[TAG_BASE_DELTA]
@@ -933,7 +934,7 @@ export default class Xapi extends XapiBase {
)
return newVdi
})::pAll()
})
const networksByNameLabelByVlan = {}
let defaultNetwork

View File

@@ -2,8 +2,7 @@ import * as openpgp from 'openpgp'
import createLogger from '@xen-orchestra/log'
import DepTree from 'deptree'
import { mapValues } from 'lodash'
import { pAll } from 'promise-toolbox'
import { asyncMapValues } from '../_asyncMapValues'
const log = createLogger('xo:config-management')
@@ -38,7 +37,7 @@ export default class ConfigManagement {
managers = subset
}
let config = JSON.stringify(await mapValues(managers, ({ exporter }, key) => exporter())::pAll())
let config = JSON.stringify(await asyncMapValues(managers, ({ exporter }) => exporter()))
if (passphrase !== undefined) {
config = Buffer.from(