import { Data } from './Trebuchet' ; export type SendFn = ( message : Data ) => void ; class MessageQueue { queue : Array < Data > = [ ] ; add ( message ) { this . queue . push ( message ) ; } clear ( ) { this . queue = [ ] ; } flush ( send ) { const startingQueueLength = this . queue . length ; this . queue . forEach ( ( message ) => { send ( message ) ; } ) ; this . queue . splice ( 0 , startingQueueLength ) ; } } export default MessageQueue ;