<commit_before>'use strict'

const _ = require('lodash')
const Promise = require('bluebird')

const { defaultContext } = require('../constants/default-task-state.js')
const { mergeCtx } = require('../ctx')

function join(...tasks) {
  let uids = []
  const accumulator = (currentCtx, task) => new Promise((resolve, reject) => {
    // TODO better checking if task/join/junction/fork
    if (task.info) {
      console.log('Joining to task: ' + task.info.name)
      // Add this task to list of uids for this join
      uids.push(task.info.uid)
    }

    // Call next task with currentCtx
    task(_.noop, currentCtx).then((results) => {
      // Resolve to a new context with a ctx merge strategy
      const newCtx = mergeCtx('join')(currentCtx, results)
      resolve(newCtx)
    })
  })

  const joinInvocator = (cb = _.noop, ctx = defaultContext) =>
    Promise.reduce(tasks, accumulator, ctx)
      .then(results => Promise.resolve(Object.assign({}, {
        type: results.type,
        tasks: uids,
        context: {
          trajectory: results.trajectory
        }
      })))
      .asCallback(cb)

  joinInvocator.info = tasks.map(task => task.info)

  return joinInvocator
}

module.exports = join
<commit_msg>join resolves with its own uid<commit_after>'use strict'

const _ = require('lodash')
const Promise = require('bluebird')

const { defaultContext } = require('../constants/default-task-state.js')
const { mergeCtx } = require('../ctx')
const hash = require('../utils/hash.js')

function join(...tasks) {
  let uids = []
  const accumulator = (currentCtx, task) => new Promise((resolve, reject) => {
    // TODO better checking if task/join/junction/fork
    if (task.info) {
      console.log('Joining to task: ' + task.info.name)
      // Add this task to list of uids for this join
      uids.push(task.info.uid)
    }

    // Call next task with currentCtx
    task(_.noop, currentCtx).then((results) => {
      // Resolve to a new context with a ctx merge strategy
      const newCtx = mergeCtx('join')(currentCtx, results)
      resolve(newCtx)
    })
  })

  const joinInvocator = (cb = _.noop, ctx = defaultContext) =>
    Promise.reduce(tasks, accumulator, ctx)
      .then(results => Promise.resolve(Object.assign({}, {
        type: results.type,
        uid: hash(uids.join('')),
        tasks: uids,
        context: {
          trajectory: results.trajectory
        }
      })))
      .asCallback(cb)

  joinInvocator.info = tasks.map(task => task.info)

  return joinInvocator
}

module.exports = join

{'fraction_non_alphanumeric': 0.14133858267716534, 'fraction_numerical': 0.0, 'mean_word_length': 2.7588757396449703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '4989670', 'n_tokens_mistral': 797, 'n_tokens_neox': 798, 'n_words': 198}