Skip to content

Commit 416b221

Browse files
yahia-kerimdelvedor
authored andcommitted
fix(TransportRequestPromise): add finally method to TransportRequestP… (#1415)
* fix(TransportRequestPromise): add finally method to TransportRequestPromise interface * fix(TransportRequestPromise): add finally method to transportReturn object * fix(TransportRequestPromise): add finally method tests
1 parent 528b90d commit 416b221

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

lib/Transport.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export interface TransportRequestCallback {
120120

121121
export interface TransportRequestPromise<T> extends Promise<T> {
122122
abort: () => void;
123+
finally(onFinally?: (() => void) | undefined | null): Promise<T>;
123124
}
124125

125126
export interface TransportGetConnectionOptions {

lib/Transport.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ class Transport {
163163
request.abort()
164164
debug('Aborting request', params)
165165
return this
166+
},
167+
finally (onFinally) {
168+
return p.finally(onFinally)
166169
}
167170
}
168171

test/unit/api.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,33 @@ test('Error (promises)', t => {
124124
})
125125
})
126126

127+
test('Finally method (promises)', t => {
128+
t.plan(1)
129+
130+
function handler (req, res) {
131+
res.setHeader('Content-Type', 'application/json;utf=8')
132+
res.end(JSON.stringify({ hello: 'world' }))
133+
}
134+
135+
buildServer(handler, ({ port }, server) => {
136+
const client = new Client({
137+
node: `http://localhost:${port}`
138+
})
139+
140+
const request = client.search({
141+
index: 'test',
142+
q: 'foo:bar'
143+
})
144+
145+
t.type(request.finally, 'function')
146+
147+
request
148+
.finally(() => {
149+
server.stop()
150+
})
151+
})
152+
})
153+
127154
test('Abort method (callback)', t => {
128155
t.plan(3)
129156

0 commit comments

Comments
 (0)