Last change
on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
649 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | import {
|
---|
| 2 | Agent,
|
---|
| 3 | ClientRequest,
|
---|
| 4 | RequestOptions,
|
---|
| 5 | AgentCallbackCallback,
|
---|
| 6 | AgentCallbackPromise,
|
---|
| 7 | AgentCallbackReturn
|
---|
| 8 | } from './index';
|
---|
| 9 |
|
---|
| 10 | type LegacyCallback = (
|
---|
| 11 | req: ClientRequest,
|
---|
| 12 | opts: RequestOptions,
|
---|
| 13 | fn: AgentCallbackCallback
|
---|
| 14 | ) => void;
|
---|
| 15 |
|
---|
| 16 | export default function promisify(fn: LegacyCallback): AgentCallbackPromise {
|
---|
| 17 | return function(this: Agent, req: ClientRequest, opts: RequestOptions) {
|
---|
| 18 | return new Promise((resolve, reject) => {
|
---|
| 19 | fn.call(
|
---|
| 20 | this,
|
---|
| 21 | req,
|
---|
| 22 | opts,
|
---|
| 23 | (err: Error | null | undefined, rtn?: AgentCallbackReturn) => {
|
---|
| 24 | if (err) {
|
---|
| 25 | reject(err);
|
---|
| 26 | } else {
|
---|
| 27 | resolve(rtn);
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | );
|
---|
| 31 | });
|
---|
| 32 | };
|
---|
| 33 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.