Skip to content

Commit 25dffa2

Browse files
committed
replace other places using awaiting with builtin functions
1 parent 9c4451a commit 25dffa2

File tree

5 files changed

+11
-26
lines changed

5 files changed

+11
-26
lines changed

lib/test/http/error-handling.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as httpProxy from "../..";
66
import * as http from "http";
77
import getPort from "../get-port";
88
import log from "../log";
9-
import { callback } from "awaiting";
109
import fetch from "node-fetch";
1110

1211
const CUSTOM_ERROR = "There was an error proxying your request";
@@ -68,15 +67,14 @@ describe("Test proxying over HTTP with latency", () => {
6867
Upgrade: "websocket",
6968
},
7069
};
71-
const f = (cb: any) => {
70+
const err = await new Promise<Error>((resolve) => {
7271
const req = http.request(options);
7372
req.end();
7473
req.on("error", (err) => {
7574
log(`request error -- ${err}`);
76-
cb(undefined, err);
75+
resolve(err);
7776
});
78-
};
79-
const err = await callback(f);
77+
});
8078
expect(err.message).toContain("socket hang up");
8179
expect(customWSErrorCalled).toBe(true);
8280
});

lib/test/http/server-sent-events.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as http from "http";
99
import getPort from "../get-port";
1010
import { createSession } from "better-sse";
1111
import { EventSource } from "eventsource";
12-
import { callback } from "awaiting";
1312
import fetch from "node-fetch";
1413

1514
describe("proxying server sent events over HTTP", () => {
@@ -60,26 +59,24 @@ describe("proxying server sent events over HTTP", () => {
6059
// These two tests leave open handles on node v18, so we disable them ONLY
6160
// with node v18.
6261
it("test receiving an SSE WITHOUT using the proxy", async () => {
63-
const f = (cb: any) => {
62+
const resp = await new Promise(resolve => {
6463
const sse = new EventSource(`http://localhost:${ports.http}/sse`);
6564
sse.addEventListener("message", ({ data }) => {
6665
sse.close();
67-
cb(undefined, JSON.parse(data));
66+
resolve(JSON.parse(data));
6867
});
69-
};
70-
const resp = await callback(f);
68+
})
7169
expect(resp).toEqual("Hello world! - 1");
7270
});
7371

7472
it("test receiving an SSE USING the proxy", async () => {
75-
const f = (cb: any) => {
73+
const resp = await new Promise(resolve => {
7674
const sse = new EventSource(`http://localhost:${ports.proxy}/sse`);
7775
sse.addEventListener("message", ({ data }) => {
7876
sse.close();
79-
cb(undefined, JSON.parse(data));
77+
resolve(JSON.parse(data));
8078
});
81-
};
82-
const resp = await callback(f);
79+
});
8380
expect(resp).toEqual("Hello world! - 2");
8481
});
8582
}

lib/test/wait.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { delay } from "awaiting";
1+
import { setTimeout } from "node:timers/promises";
22

33
export default async function wait({ until }: { until: Function }) {
44
let d = 5;
55
while (!(await until())) {
6-
await delay(d);
6+
await setTimeout(d);
77
d = Math.min(1000, d * 1.2);
88
}
99
}

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"@types/ws": "^8.18.1",
3838
"async": "^3.2.6",
3939
"auto-changelog": "^2.5.0",
40-
"awaiting": "^3.0.0",
4140
"better-sse": "^0.14.1",
4241
"body-parser": "^2.2.0",
4342
"compression": "^1.8.0",

pnpm-lock.yaml

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)