Skip to content

Commit 9c4451a

Browse files
committed
use once from events
1 parent f8beba7 commit 9c4451a

9 files changed

+12
-29
lines changed

lib/test/balancer/simple-balancer-with-websockets.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pnpm test ./simple-balancer-with-websockets.test.ts
77
import * as http from "http";
88
import * as httpProxy from "../..";
99
import getPort from "../get-port";
10-
import { once } from "../wait";
10+
import { once } from "events";
1111
import fetch from "node-fetch";
1212

1313
describe("A simple round-robin load balancer that supports websockets", () => {

lib/test/lib/http-proxy.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import * as net from "net";
1111
import WebSocket, { WebSocketServer } from "ws";
1212
import { Server } from "socket.io";
1313
import { io as socketioClient } from "socket.io-client";
14-
import wait, { once } from "../wait";
14+
import wait from "../wait";
15+
import { once } from "events";
1516

1617
const ports: { [port: string]: number } = {};
1718
let portIndex = -1;

lib/test/wait.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { callback, delay } from "awaiting";
1+
import { delay } from "awaiting";
22

33
export default async function wait({ until }: { until: Function }) {
44
let d = 5;
@@ -7,23 +7,3 @@ export default async function wait({ until }: { until: Function }) {
77
d = Math.min(1000, d * 1.2);
88
}
99
}
10-
11-
import type { EventEmitter } from "events";
12-
13-
export async function once(obj: EventEmitter, event: string): Promise<any> {
14-
if (obj == null) {
15-
throw Error("once -- obj is undefined");
16-
}
17-
if (typeof obj.once != "function") {
18-
throw Error("once -- obj.once must be a function");
19-
}
20-
let val: any[] = [];
21-
function wait(cb: Function): void {
22-
obj.once(event, function (...args): void {
23-
val = args;
24-
cb();
25-
});
26-
}
27-
await callback(wait);
28-
return val;
29-
}

lib/test/websocket/latent-websocket-proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pnpm test latent-websocket-proxy.test.ts
66

77
import * as httpProxy from "../..";
88
import getPort from "../get-port";
9-
import { once } from "../wait";
9+
import { once } from "events";
1010
import http, { createServer } from "http";
1111
import { Server } from "socket.io";
1212
import { io as socketioClient } from "socket.io-client";

lib/test/websocket/simple-websocket-proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as http from "http";
1515
import * as httpProxy from "../..";
1616
import log from "../log";
1717
import getPort from "../get-port";
18-
import { once } from "../wait";
18+
import { once } from "events";
1919

2020
describe("Example of simple proxying of a WebSocket", () => {
2121
let ports: Record<'ws' | 'proxy', number>;

lib/test/websocket/standalone-websocket-proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pnpm test ./standalone-websocket-proxy.test.ts
66

77
import * as httpProxy from "../..";
88
import getPort from "../get-port";
9-
import { once } from "../wait";
9+
import { once } from "events";
1010
import http, { createServer } from "http";
1111
import { Server } from "socket.io";
1212
import { io as socketioClient } from "socket.io-client";

lib/test/websocket/websocket-load.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ pnpm test websocket-load.test.ts
77
import * as http from "http";
88
import * as httpProxy from "../..";
99
import getPort from "../get-port";
10-
import wait, { once } from "../wait";
10+
import wait from "../wait";
11+
import { once } from "events";
1112

1213
describe("Load testing proxying a WebSocket", () => {
1314
let ports: Record<'ws' | 'proxy', number>;

lib/test/websocket/websocket-proxy-websocket.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import * as httpProxy from "../..";
1717
import getPort from "../get-port";
1818
import { Server } from "socket.io";
1919
import { io as socketioClient } from "socket.io-client";
20-
import { once } from "../wait";
20+
import { once } from "events";
2121

2222
describe("Multilevel Proxying of a Websocket using Socket.io", () => {
2323
let ports: Record<'socketio' | 'inner' | 'outer', number>;

lib/test/websocket/websocket-proxy.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ that no sockets leak.
1313
import * as httpProxy from "../..";
1414
import log from "../log";
1515
import getPort from "../get-port";
16-
import wait, { once } from "../wait";
16+
import wait from "../wait";
17+
import { once } from "events";
1718
import { createServer } from "http";
1819
import { Server } from "socket.io";
1920
import { io as socketioClient } from "socket.io-client";

0 commit comments

Comments
 (0)