import { IMessage } from "./message" ; export interface IMessageQueue { getLastReadAt ( ) : number ; addMessage ( message ) : void ; readMessage ( ) : IMessage | undefined ; getMessages ( ) : IMessage [ ] ; } export class MessageQueue implements IMessageQueue { private lastReadAt : number = new Date ( ) . getTime ( ) ; private readonly messages : IMessage [ ] = [ ] ; public getLastReadAt ( ) { return this . lastReadAt ; } public addMessage ( message ) { this . messages . push ( message ) ; } public readMessage ( ) { if ( this . messages . length > 0 ) { this . lastReadAt = new Date ( ) . getTime ( ) ; return this . messages . shift ( ) ; } return undefined ; } public getMessages ( ) { return this . messages ; } }