Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
34 lines
649 B
Plaintext
34 lines
649 B
Plaintext
import {
|
|
Agent,
|
|
ClientRequest,
|
|
RequestOptions,
|
|
AgentCallbackCallback,
|
|
AgentCallbackPromise,
|
|
AgentCallbackReturn
|
|
} from './index';
|
|
|
|
type LegacyCallback = (
|
|
req: ClientRequest,
|
|
opts: RequestOptions,
|
|
fn: AgentCallbackCallback
|
|
) => void;
|
|
|
|
export default function promisify(fn: LegacyCallback): AgentCallbackPromise {
|
|
return function(this: Agent, req: ClientRequest, opts: RequestOptions) {
|
|
return new Promise((resolve, reject) => {
|
|
fn.call(
|
|
this,
|
|
req,
|
|
opts,
|
|
(err: Error | null | undefined, rtn?: AgentCallbackReturn) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(rtn);
|
|
}
|
|
}
|
|
);
|
|
});
|
|
};
|
|
}
|