Skip to content

Commit f3e1f5e

Browse files
fix(sio): call adapter.init() when creating each namespace
The init() method of the adapter will now be called when creating a namespace with `io.of(<the-namespace>)`. Note: any promise rejection is silently caught, as I don't see how we could properly expose the promise. ```js const io = new Server({ adapter: myAdapter }); // under the hood, this: // - implicitly creates the main namespace (/) // - creates an instance of `myAdapter` for the main namespace // - calls `myAdapter.init()` (with this change) ``` Related: - #3662 - socketio/socket.io-postgres-adapter#16
1 parent e975492 commit f3e1f5e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/socket.io/lib/namespace.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ export class Namespace<
197197
_initAdapter(): void {
198198
// @ts-ignore
199199
this.adapter = new (this.server.adapter()!)(this);
200+
201+
Promise.resolve(this.adapter.init()).catch((err) => {
202+
debug("error while initializing adapter: %s", err);
203+
});
200204
}
201205

202206
/**

0 commit comments

Comments
 (0)