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
This commit is contained in:
Yahia Kerim
2021-03-22 11:50:15 +01:00
committed by GitHub
parent 6a30cd9955
commit ab3e809fc2
3 changed files with 31 additions and 0 deletions

1
lib/Transport.d.ts vendored
View File

@ -120,6 +120,7 @@ export interface TransportRequestCallback {
export interface TransportRequestPromise<T> extends Promise<T> {
abort: () => void;
finally(onFinally?: (() => void) | undefined | null): Promise<T>;
}
export interface TransportGetConnectionOptions {

View File

@ -163,6 +163,9 @@ class Transport {
request.abort()
debug('Aborting request', params)
return this
},
finally (onFinally) {
return p.finally(onFinally)
}
}

View File

@ -124,6 +124,33 @@ test('Error (promises)', t => {
})
})
test('Finally method (promises)', t => {
t.plan(1)
function handler (req, res) {
res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
const client = new Client({
node: `http://localhost:${port}`
})
const request = client.search({
index: 'test',
q: 'foo:bar'
})
t.type(request.finally, 'function')
request
.finally(() => {
server.stop()
})
})
})
test('Abort method (callback)', t => {
t.plan(3)