<commit_before>
var Async = require('async')
var seneca = require('seneca')()
seneca.use('seneca-sm')
var config = require('./smconfig.js').config

seneca.add('role:content, context:document, cmd: triage', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: triage'})
})
.add('role:content, context:document, cmd: review', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: review'})
})
.add('role:content, context:document, cmd: approve', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: approve'})
})
.add('role:content, context:document, cmd: schedule', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: schedule'})
})
.add('role:content, context:document, cmd: approve_final', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: approve_final'})
})

Async.series({
  create_instance: function (callback) {
    seneca.act("role: 'sm', create: 'instance'", config, function (err, context) {
      console.log('created the state machine:', config.name)
      callback(err)
    })
  },
  verify_state: function (callback) {
    seneca.act('role:' + config.name + ', get:context', function (err, context) {
      console.log('current state: ', context.current_status)
      callback(err)
    })
  },
  triage_document: function (callback) {
    console.log('change state to triage')
    seneca.act('role:' + config.name + ', cmd: triage', function(err, context) {
      console.log('state changed')
      callback(err)
    })
  },
  verify_triage_state: function (callback) {
    seneca.act('role:' + config.name + ', get:context', function (err, context) {
      console.log('current state: ', context.current_status)
      callback(err)
    })
  }
},
function (err, results) {
//   console.log(err, results)
})<commit_msg>simplified code<commit_after>
var Async = require('async')
var seneca = require('seneca')()
seneca.use('seneca-sm')
var config = require('./smconfig.js').config

seneca.add('role:content, context:document, cmd: triage', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: triage'})
})
.add('role:content, context:document, cmd: review', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: review'})
})
.add('role:content, context:document, cmd: approve', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: approve'})
})
.add('role:content, context:document, cmd: schedule', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: schedule'})
})
.add('role:content, context:document, cmd: approve_final', function(err, respond) {
  respond(null, {command: 'execute command: role:content, context:document, cmd: approve_final'})
})

function createInstance(callback) {
  seneca.act("role: 'sm', create: 'instance'", config, function (err, context) {
    console.log('created the state machine:', config.name)
    callback(err)
  })
}

function changeState(state, callback) {
  console.log('change state to ', state)
  seneca.act('role:' + config.name + ', cmd: ' + state, function(err, context) {
    console.log('state changed')
    callback(err)
  })
}

function verifyState(callback) {
  seneca.act('role:' + config.name + ', get:context', function (err, context) {
    console.log('current state: ', context.current_status)
    callback(err)
  })
}

Async.series([
  createInstance,
  function (callback) { changeState('triage', callback) },
  verifyState,
  function (callback) { changeState('review', callback) },
  verifyState,
  // function (callback) { changeState('triage', callback) }
  ],
function (err, results) {
//   console.log(err, results)
})
{'fraction_non_alphanumeric': 0.16952141057934508, 'fraction_numerical': 0.0, 'mean_word_length': 5.373996789727127, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2570637', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1219, 'n_words': 293}