MCPcopy
hub / github.com/socketio/socket.io / init

Function init

packages/socket.io-redis-streams-emitter/test/util.ts:102–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

100}
101
102async function init() {
103 const redisClient = await initRedisClient();
104
105 const httpServer = createServer();
106 const io = new Server(httpServer, {
107 adapter: createAdapter(redisClient, {
108 readCount: 1, // return as soon as possible
109 }),
110 });
111
112 return new Promise<{
113 io: Server;
114 socket: ServerSocket;
115 clientSocket: ClientSocket;
116 cleanup: () => void;
117 }>((resolve) => {
118 httpServer.listen(() => {
119 const port = (httpServer.address() as AddressInfo).port;
120 const clientSocket = ioc(`http://localhost:${port}`);
121
122 io.on("connection", async (socket) => {
123 resolve({
124 io,
125 socket,
126 clientSocket,
127 cleanup: () => {
128 io.close();
129 clientSocket.disconnect();
130 redisClient.quit();
131 },
132 });
133 });
134 });
135 });
136}
137
138export async function setup() {
139 const results = await Promise.all([init(), init(), init()]);

Callers 1

setupFunction · 0.70

Calls 7

closeMethod · 0.95
initRedisClientFunction · 0.85
createServerFunction · 0.85
createAdapterFunction · 0.85
listenMethod · 0.80
onMethod · 0.45
disconnectMethod · 0.45

Tested by

no test coverage detected