<commit_before>const {remote, ipcRenderer} = req('electron')

module.exports = store => {
  store.registerModule('workers', {
    namespaced: true,
    state: () => ({
      queue: [],
      workers: []
    }),

    mutations: {
      enqueue({queue}, {task}) {
        queue.push(task)
      },

      dequeue({queue}) {
        queue.shift()
      },

      worker(state) {
        let workers = state.workers.filter(win => !win.isDestroyed())

        if(workers.length >= 4) return
        let win = new remote.BrowserWindow({show: false})
        workers.push(win)
        state.workers = workers

        let url = new URL(window.location)
        url.hash = 'worker'
        win.loadURL('' + url)
      }
    },

    actions: {
      task({commit}, {task}) {
        commit('enqueue', {task})
        commit('worker')
      },

      issue({state, commit}, {worker}) {
        if(state.queue.length) {
          let task = state.queue[0]
          commit('dequeue')
          worker.send('task', task)
        } else {
          worker.send('task')
        }
      }
    }
  })

  ipcRenderer.on('request-task', (event, workerId) => {
    let worker = remote.webContents.fromId(workerId)
    store.dispatch('workers/issue', {worker})<commit_msg>Store window IDs instead of window objects<commit_after>const {remote, ipcRenderer} = req('electron')

module.exports = store => {
  store.registerModule('workers', {
    namespaced: true,
    state: () => ({
      queue: [],
      workers: []
    }),

    mutations: {
      enqueue({queue}, {task}) {
        queue.push(task)
      },

      dequeue({queue}) {
        queue.shift()
      },

      worker(state) {
        let workers = state.workers.filter(win =>
          remote.BrowserWindow.fromId(win) &&
          !remote.BrowserWindow.fromId(win).isDestroyed()
        )

        if(workers.length >= 4) return
        let win = new remote.BrowserWindow({show: false})
        workers.push(win.id)
        state.workers = workers

        let url = new URL(window.location)
        url.hash = 'worker'
        win.loadURL('' + url)
      }
    },

    actions: {
      task({commit}, {task}) {
        commit('enqueue', {task})
        commit('worker')
      },

      issue({state, commit}, {worker}) {
        if(state.queue.length) {
          let task = state.queue[0]
          commit('dequeue')
          worker.send('task', task)
        } else {
          worker.send('task')
        }
      }
    }
  })

  ipcRenderer.on('request-task', (event, workerId) => {
    let worker = remote.webContents.fromId(workerId)
    store.dispatch('workers/issue', {worker})
{'fraction_non_alphanumeric': 0.15855513307984792, 'fraction_numerical': 0.001520912547528517, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4697889', 'n_tokens_mistral': 812, 'n_tokens_neox': 788, 'n_words': 142}