{"size": 398, "ext": "js", "max_stars_repo_path": "lib/ws2/flush_send_buffer.js", "max_stars_repo_name": "robertkowalski/bfx-api-node-core", "max_stars_repo_stars_event_min_datetime": "2020-02-01T20:27:18.000Z", "max_stars_repo_stars_event_max_datetime": "2021-05-19T04:31:32.000Z", "max_issues_repo_path": "lib/ws2/flush_send_buffer.js", "max_issues_repo_name": "robertkowalski/bfx-api-node-core", "max_issues_repo_issues_event_min_datetime": "2020-01-30T22:48:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-22T13:05:47.000Z", "max_forks_repo_path": "lib/ws2/flush_send_buffer.js", "max_forks_repo_name": "robertkowalski/bfx-api-node-core", "max_forks_repo_forks_event_min_datetime": "2019-05-02T02:53:28.000Z", "max_forks_repo_forks_event_max_datetime": "2021-04-21T19:39:12.000Z"}
{"max_stars_count": 4, "max_issues_count": 6, "max_forks_count": 8, "avg_line_length": 16.5833333333, "max_line_length": 63, "alphanum_fraction": 0.5904522613}
'use strict'

const debug = require('debug')('bfx:api:ws2:flush_send_buffer')
const send = require('./send')

module.exports = (state = {}) => {
  const { sendBuffer = [] } = state

  if (sendBuffer.length === 0) {
    return state
  }

  debug('flushing %d packets...', sendBuffer.length)

  sendBuffer.forEach(msg => {
    send(state, msg)
  })

  return {
    ...state,
    sendBuffer: []
  }
}
