<commit_before>import createThreadReducer from '~utils/createThreadReducer'

import {
  IPC_IPFS_START,
  IPC_IPFS_CACHE_CIDS,
  IPC_IPFS_SHARE_FS_FILE,
  IPC_IPFS_SHARE_OBJECT,
  IPC_METABIN_GATE_SUBSCRIBE,
  IPC_METABIN_GATE_SEND,
  IPC_METABIN_GATE_UNSUBSCRIBE,
  IPC_IPFS_GET_INFO,
  IPC_METABIN_GET_RECIEVED_DATA_CACHE
} from '~data/ipcTypes'

import startIpfsDaemon from './ipfs.thread/startIpfsDaemon'

import {
  getIpfsInfo,
  ipfsShareFsFile,
  ipfsShareObject,
  ipfsCacheFilesByCIDs
} from './ipfs.thread/ipfsApi'

import {
  metabinSubscribe,
  metabinSend,
  metabinUnsubscribe,
  metabinGetRecievedDataCache
} from './ipfs.thread/metabinApi'

let ipfsDaemonPromise

const reducer = ({ type, payload }) => {
  const args = { ipfsDaemonPromise, payload }
  switch (type) {
    case IPC_IPFS_START:
      ipfsDaemonPromise = startIpfsDaemon(payload)
      return
    case IPC_IPFS_GET_INFO:
      return getIpfsInfo(args)
    case IPC_IPFS_CACHE_CIDS:
      return ipfsCacheFilesByCIDs(args)
    case IPC_IPFS_SHARE_FS_FILE:
      return ipfsShareFsFile(args)
    case IPC_IPFS_SHARE_OBJECT:
      return ipfsShareObject(args)
    case IPC_METABIN_GATE_SUBSCRIBE:
      return metabinSubscribe(args)
    case IPC_METABIN_GATE_SEND:
      return metabinSend(args)
    case IPC_METABIN_GATE_UNSUBSCRIBE:
      return metabinUnsubscribe(args)
    case IPC_METABIN_GET_RECIEVED_DATA_CACHE:
      return metabinGetRecievedDataCache(args)
    default:
      throw new Error('ipfs.thread: Unknown message type.')
  }
}

createThreadReducer(reducer)

process.on('disconnect', async () => {
  const daemon = await ipfsDaemonPromise
  daemon.stop()
})<commit_msg>refactor(): handle ipfs daemon errors  on exit<commit_after>import createThreadReducer from '~utils/createThreadReducer'

import {
  IPC_IPFS_START,
  IPC_IPFS_CACHE_CIDS,
  IPC_IPFS_SHARE_FS_FILE,
  IPC_IPFS_SHARE_OBJECT,
  IPC_METABIN_GATE_SUBSCRIBE,
  IPC_METABIN_GATE_SEND,
  IPC_METABIN_GATE_UNSUBSCRIBE,
  IPC_IPFS_GET_INFO,
  IPC_METABIN_GET_RECIEVED_DATA_CACHE
} from '~data/ipcTypes'

import startIpfsDaemon from './ipfs.thread/startIpfsDaemon'

import {
  getIpfsInfo,
  ipfsShareFsFile,
  ipfsShareObject,
  ipfsCacheFilesByCIDs
} from './ipfs.thread/ipfsApi'

import {
  metabinSubscribe,
  metabinSend,
  metabinUnsubscribe,
  metabinGetRecievedDataCache
} from './ipfs.thread/metabinApi'

let ipfsDaemonPromise

const reducer = ({ type, payload }) => {
  const args = { ipfsDaemonPromise, payload }
  switch (type) {
    case IPC_IPFS_START:
      ipfsDaemonPromise = startIpfsDaemon(payload)
      return
    case IPC_IPFS_GET_INFO:
      return getIpfsInfo(args)
    case IPC_IPFS_CACHE_CIDS:
      return ipfsCacheFilesByCIDs(args)
    case IPC_IPFS_SHARE_FS_FILE:
      return ipfsShareFsFile(args)
    case IPC_IPFS_SHARE_OBJECT:
      return ipfsShareObject(args)
    case IPC_METABIN_GATE_SUBSCRIBE:
      return metabinSubscribe(args)
    case IPC_METABIN_GATE_SEND:
      return metabinSend(args)
    case IPC_METABIN_GATE_UNSUBSCRIBE:
      return metabinUnsubscribe(args)
    case IPC_METABIN_GET_RECIEVED_DATA_CACHE:
      return metabinGetRecievedDataCache(args)
    default:
      throw new Error('ipfs.thread: Unknown message type.')
  }
}

createThreadReducer(reducer)

process.on('disconnect', async () => {
  try {
    const daemon = await ipfsDaemonPromise
    daemon.stop()
  } catch (e) {
    console.error(e)
  }
})
{'fraction_non_alphanumeric': 0.0743559718969555, 'fraction_numerical': 0.0, 'mean_word_length': 4.484751203852327, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4205243', 'n_tokens_mistral': 1379, 'n_tokens_neox': 1332, 'n_words': 206}