/**
 * A rate limiter to make sure that a client can only request help for one task within a time window.
 */ export class RateLimiter { private readonly requestMap = new Map < string , number > ( ) ; param windowMSec constructor ( private readonly windowMSec ) { } param clientId param messages returns public filter ( clientId , messages ) { const approvedList = [ ] ; const currentTime = Date . now ( ) ; for ( const message of messages ) { const key = `${ clientId }/${ message }` ; if ( ! this . requestMap . has ( key ) ) { this . requestMap . set ( key , currentTime ) ; approvedList . push ( message ) ; } else if ( this . requestMap . get ( key ) ! + this . windowMSec > currentTime ) { continue ; } else { this . requestMap . set ( key , currentTime ) ; approvedList . push ( message ) ; } } return approvedList ; } }