chore: dont wrap unnecessary with fromCallback
This commit is contained in:
@@ -389,7 +389,7 @@ export default class RemoteHandlerAbstract {
|
||||
async test(): Promise<Object> {
|
||||
const SIZE = 1024 * 1024 * 10
|
||||
const testFileName = normalizePath(`${Date.now()}.test`)
|
||||
const data = await fromCallback(cb => randomBytes(SIZE, cb))
|
||||
const data = await fromCallback(randomBytes, SIZE)
|
||||
let step = 'write'
|
||||
try {
|
||||
const writeStart = process.hrtime()
|
||||
|
||||
@@ -86,7 +86,7 @@ handlers.forEach(url => {
|
||||
describe('#createOutputStream()', () => {
|
||||
it('creates parent dir if missing', async () => {
|
||||
const stream = await handler.createOutputStream('dir/file')
|
||||
await fromCallback(cb => pipeline(createTestDataStream(), stream, cb))
|
||||
await fromCallback(pipeline, createTestDataStream(), stream)
|
||||
await expect(await handler.readFile('dir/file')).toEqual(TEST_DATA)
|
||||
})
|
||||
})
|
||||
@@ -106,7 +106,7 @@ handlers.forEach(url => {
|
||||
describe('#createWriteStream()', () => {
|
||||
testWithFileDescriptor('file', 'wx', async ({ file, flags }) => {
|
||||
const stream = await handler.createWriteStream(file, { flags })
|
||||
await fromCallback(cb => pipeline(createTestDataStream(), stream, cb))
|
||||
await fromCallback(pipeline, createTestDataStream(), stream)
|
||||
await expect(await handler.readFile('file')).toEqual(TEST_DATA)
|
||||
})
|
||||
|
||||
|
||||
@@ -386,7 +386,7 @@ async function call(args) {
|
||||
printProgress
|
||||
)
|
||||
|
||||
return fromCallback(cb => pump(response, progress, output, cb))
|
||||
return fromCallback(pump, response, progress, output)
|
||||
}
|
||||
|
||||
if (key === '$sendTo') {
|
||||
|
||||
@@ -16,7 +16,7 @@ const CACHE_FILE = './ldap.cache.conf'
|
||||
execPromise(async args => {
|
||||
const config = await promptSchema(
|
||||
configurationSchema,
|
||||
await fromCallback(cb => readFile(CACHE_FILE, 'utf-8', cb)).then(
|
||||
await fromCallback(readFile, CACHE_FILE, 'utf-8').then(
|
||||
JSON.parse,
|
||||
() => ({})
|
||||
)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import fromCallback from 'promise-toolbox/fromCallback'
|
||||
import { execFile } from 'child_process'
|
||||
|
||||
export const read = key =>
|
||||
fromCallback(cb => execFile('xenstore-read', [key], cb))
|
||||
export const read = key => fromCallback(execFile, 'xenstore-read', [key])
|
||||
|
||||
@@ -168,7 +168,7 @@ runJob.params = {
|
||||
async function handleGetAllLogs(req, res) {
|
||||
const logs = await this.getBackupNgLogs()
|
||||
res.set('Content-Type', 'application/json')
|
||||
return fromCallback(cb => pipeline(createNdJsonStream(logs), res, cb))
|
||||
return fromCallback(pipeline, createNdJsonStream(logs), res)
|
||||
}
|
||||
|
||||
export function getAllLogs({ ndjson = false }) {
|
||||
|
||||
@@ -38,7 +38,7 @@ exportConfig.permission = 'admin'
|
||||
function handleGetAllObjects(req, res, { filter, limit }) {
|
||||
const objects = this.getObjects({ filter, limit })
|
||||
res.set('Content-Type', 'application/json')
|
||||
return fromCallback(cb => pipeline(createNdJsonStream(objects), res, cb))
|
||||
return fromCallback(pipeline, createNdJsonStream(objects), res)
|
||||
}
|
||||
|
||||
export function getAllObjects({ filter, limit, ndjson = false }) {
|
||||
|
||||
@@ -467,7 +467,7 @@ const setUpProxies = (express, opts, xo) => {
|
||||
const webSocketServer = new WebSocket.Server({
|
||||
noServer: true,
|
||||
})
|
||||
xo.on('stop', () => fromCallback(cb => webSocketServer.close(cb)))
|
||||
xo.on('stop', fromCallback.call(webSocketServer, 'close'))
|
||||
|
||||
express.on('upgrade', (req, socket, head) => {
|
||||
const { url } = req
|
||||
@@ -508,7 +508,7 @@ const setUpApi = (webServer, xo, config) => {
|
||||
|
||||
noServer: true,
|
||||
})
|
||||
xo.on('stop', () => fromCallback(cb => webSocketServer.close(cb)))
|
||||
xo.on('stop', fromCallback.call(webSocketServer, 'close'))
|
||||
|
||||
const onConnection = (socket, upgradeReq) => {
|
||||
const { remoteAddress } = upgradeReq.socket
|
||||
@@ -577,7 +577,7 @@ const setUpConsoleProxy = (webServer, xo) => {
|
||||
const webSocketServer = new WebSocket.Server({
|
||||
noServer: true,
|
||||
})
|
||||
xo.on('stop', () => fromCallback(cb => webSocketServer.close(cb)))
|
||||
xo.on('stop', fromCallback.call(webSocketServer, 'close'))
|
||||
|
||||
webServer.on('upgrade', async (req, socket, head) => {
|
||||
const matches = CONSOLE_PROXY_PATH_RE.exec(req.url)
|
||||
@@ -670,7 +670,7 @@ export default async function main(args) {
|
||||
const xo = new Xo(config)
|
||||
|
||||
// Register web server close on XO stop.
|
||||
xo.on('stop', () => fromCallback(cb => webServer.stop(cb)))
|
||||
xo.on('stop', fromCallback.call(webServer, 'stop'))
|
||||
|
||||
// Connects to all registered servers.
|
||||
await xo.start()
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('streamToExistingBuffer()', () => {
|
||||
it('read the content of a stream in a buffer', async () => {
|
||||
const stream = createReadStream(__filename)
|
||||
|
||||
const expected = await fromCallback(cb => readFile(__filename, 'utf-8', cb))
|
||||
const expected = await fromCallback(readFile, __filename, 'utf-8')
|
||||
|
||||
const buf = Buffer.allocUnsafe(expected.length + 1)
|
||||
buf[0] = 'A'.charCodeAt()
|
||||
|
||||
@@ -364,7 +364,7 @@ export const throwFn = error => () => {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export const tmpDir = () => fromCallback(cb => tmp.dir(cb))
|
||||
export const tmpDir = () => fromCallback(tmp.dir)
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
|
||||
@@ -432,7 +432,7 @@ export default class Health extends Component {
|
||||
}
|
||||
|
||||
const [, value, xml] = matches
|
||||
return fromCallback(cb => xml2js.parseString(xml, cb)).then(result => {
|
||||
return fromCallback(xml2js.parseString, xml).then(result => {
|
||||
const object = mapValues(result && result.variable, value =>
|
||||
get(value, '[0].$.value')
|
||||
)
|
||||
|
||||
@@ -7,7 +7,7 @@ const _getPackages = scope => {
|
||||
const inScope = scope !== undefined
|
||||
const relativeDir = inScope ? scope : 'packages'
|
||||
const dir = `${ROOT_DIR}/${relativeDir}`
|
||||
return fromCallback(cb => fs.readdir(dir, cb)).then(names =>
|
||||
return fromCallback(fs.readdir, dir).then(names =>
|
||||
names.map(name => ({
|
||||
dir: `${dir}/${name}`,
|
||||
name: inScope ? `${scope}/${name}` : name,
|
||||
@@ -40,14 +40,13 @@ exports.getPackages = (readPackageJson = false) => {
|
||||
const noop = (exports.noop = () => {})
|
||||
|
||||
const readFile = (exports.readFile = file =>
|
||||
fromCallback(cb => fs.readFile(file, 'utf8', cb)))
|
||||
fromCallback(fs.readFile, file, 'utf8'))
|
||||
|
||||
exports.unlink = path =>
|
||||
fromCallback(cb => fs.unlink(path, cb)).catch(error => {
|
||||
fromCallback(fs.unlink, path).catch(error => {
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error
|
||||
}
|
||||
})
|
||||
|
||||
exports.writeFile = (file, data) =>
|
||||
fromCallback(cb => fs.writeFile(file, data, cb))
|
||||
exports.writeFile = (file, data) => fromCallback(fs.writeFile, file, data)
|
||||
|
||||
Reference in New Issue
Block a user