export class SocketSessionMap < Session > { public sessions : { [ id ] : Promise < Session > ; } = { } ; constructor ( private options ) { } setup ( io ) { io . on ( 'connection' , async ( client ) => { const id = client . id ; if ( ! this . sessions [ id ] ) { this . sessions [ id ] = this . options . createSession ( client ) ; client . once ( 'disconnect' , ( ) => { if ( this . sessions [ id ] ) { delete this . sessions [ id ] ; } } ) ; } } ) ; } async getSession ( socket ) { const promise = this . sessions [ socket . id ] ; return promise ?? null ; } }