This repository has been archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert diag API to async/await (#1157)
License: MIT Signed-off-by: Alan Shaw <[email protected]>
- Loading branch information
Alan Shaw
authored
Nov 14, 2019
1 parent
5110423
commit 0e01187
Showing
5 changed files
with
47 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
const configure = require('../lib/configure') | ||
|
||
module.exports = (send) => { | ||
return promisify((opts, callback) => { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
module.exports = configure(({ ky }) => { | ||
return options => { | ||
options = options || {} | ||
|
||
send({ | ||
path: 'diag/cmds', | ||
qs: opts | ||
}, callback) | ||
}) | ||
} | ||
const searchParams = new URLSearchParams(options.searchParams) | ||
if (options.verbose != null) searchParams.set('verbose', options.verbose) | ||
|
||
return ky.get('diag/cmds', { | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams | ||
}).json() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
'use strict' | ||
|
||
const moduleConfig = require('../utils/module-config') | ||
const callbackify = require('callbackify') | ||
|
||
module.exports = (arg) => { | ||
const send = moduleConfig(arg) | ||
|
||
return { | ||
net: require('./net')(send), | ||
sys: require('./sys')(send), | ||
cmds: require('./cmds')(send) | ||
} | ||
} | ||
module.exports = config => ({ | ||
net: callbackify.variadic(require('./net')(config)), | ||
sys: callbackify.variadic(require('./sys')(config)), | ||
cmds: callbackify.variadic(require('./cmds')(config)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
const configure = require('../lib/configure') | ||
|
||
module.exports = (send) => { | ||
return promisify((opts, callback) => { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
module.exports = configure(({ ky }) => { | ||
return options => { | ||
options = options || {} | ||
|
||
send({ | ||
path: 'diag/net', | ||
qs: opts | ||
}, callback) | ||
}) | ||
} | ||
return ky.get('diag/net', { | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams: options.searchParams | ||
}).json() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,16 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
const configure = require('../lib/configure') | ||
|
||
module.exports = (send) => { | ||
return promisify((opts, callback) => { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
module.exports = configure(({ ky }) => { | ||
return options => { | ||
options = options || {} | ||
|
||
send({ | ||
path: 'diag/sys', | ||
qs: opts | ||
}, callback) | ||
}) | ||
} | ||
return ky.get('diag/sys', { | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams: options.searchParams | ||
}).json() | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters