github.com/christoph-karpowicz/db_mediator@v0.0.0-20210207102849-61a28a1071d8/web/src/ws/request_pool.tsx (about) 1 import WSRequest from './request' 2 3 interface PoolObject { 4 [key: string]: any 5 } 6 7 class WSRequestPool { 8 private _pool: PoolObject; 9 10 constructor() { 11 this._pool = {}; 12 } 13 14 public append(req: WSRequest): void { 15 this._pool[req.getId()] = null; 16 } 17 18 public respond(response: { ID: string }): void { 19 this._pool[response.ID] = response; 20 } 21 22 public hasResponse(reqId: string): boolean { 23 return this._pool[reqId] != null; 24 } 25 26 public poll(reqId: string): object { 27 const response = this._pool[reqId]; 28 delete this._pool[reqId]; 29 return response; 30 } 31 32 } 33 34 export default WSRequestPool;