Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d6e4974

Browse files
committed
feat: Ping implementation
1 parent 3d468f3 commit d6e4974

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/ping.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ const promisify = require('promisify-es6')
44
const moduleConfig = require('./utils/module-config')
55
const streamToValue = require('./utils/stream-to-value')
66

7+
// Transform the response stream to a value:
8+
// [{ Success: <boolean>, Time: <number>, Text: <string> }]
9+
const transform = (res, callback) => {
10+
streamToValue(res, (err, res) => {
11+
if (err) {
12+
return callback(err)
13+
}
14+
15+
callback(null, res)
16+
})
17+
}
18+
719
module.exports = (arg) => {
820
const send = moduleConfig(arg)
921

@@ -22,24 +34,10 @@ module.exports = (arg) => {
2234
opts.n = 1
2335
}
2436

25-
const request = {
37+
send.andTransform({
2638
path: 'ping',
2739
args: id,
2840
qs: opts
29-
}
30-
31-
// Transform the response stream to a value:
32-
// [{ Success: <boolean>, Time: <number>, Text: <string> }]
33-
const transform = (res, callback) => {
34-
streamToValue(res, (err, res) => {
35-
if (err) {
36-
return callback(err)
37-
}
38-
39-
callback(null, res)
40-
})
41-
}
42-
43-
send.andTransform(request, transform, callback)
41+
}, transform, callback)
4442
})
4543
}

0 commit comments

Comments
 (0)